The problem is that your scripts can run in different contexts. For example, the user may be recognized as local and the script will begin to be executed on his behalf. Often, Group Policy scripts run on behalf of the system user, and so on. Among other things, you are running a script with a different system environment.
Before starting the script, when you have already connected to the resource, it is worth checking the environment variables that are important for you to answer the question where and with what rights and in what environment your script is executed. For a number of systems, in particular, Windows 7 has temporary variables, "Volatile".
ReadEnv.vbs:
Set WshShell = CreateObject("WScript.Shell")
Set WshEnv = WshShell.Environment
WScript.Echo "WINDIR=" & WshEnv.Item("WINDIR") & vbCrLf &_
vbCrLf
Set WshShell = CreateObject("WScript.Shell")
WScript.Echo "Environment System:" & vbCrLf &_
"..............................................."
For Each IEnv In WshShell.Environment("System")
WScript.Echo IEnv
Next
WScript.Echo vbCrLf & "Environment User:" & vbCrLf &_
"..............................................."
For Each IEnv In WshShell.Environment("User")
WScript.Echo IEnv
Next
WScript.Echo vbCrLf & "Environment Volatile:" & vbCrLf &_
"..............................................."
For Each IEnv In WshShell.Environment("Volatile")
WScript.Echo IEnv
Next
WScript.Echo vbCrLf & "Environment Process:" & vbCrLf &_
"..............................................."
For Each IEnv In WshShell.Environment("Process")
WScript.Echo IEnv
Next
view:
cscript ReadEnv.vbs | more
save to file:
cscript ReadEnv.vbs >> out.txt
If you do not care from which user your script is executed, you can add a line to it
psexec //YourRemoteStationName reg ADD HKCU\Software\Sysinternals\PSexec /v EulaAccepted /t REG_DWORD /d 1 /f
in this case, you will receive a key installation at the remote station and
to install the key if psexec runs local:
reg ADD HKCU\Software\Sysinternals\PSexec /v EulaAccepted /t REG_DWORD /d 1 /f
reg ADD HKCU\Software\Sysinternals\PSexec /v EulaAccepted /t REG_DWORD /d 1 /f – STTR – 2019-06-13T14:29:31.813
@STTR - You should submit an answer – Ramhound – 2019-06-13T14:47:20.043
@STTR you mean I need to add that registry key value? Is that what I should type in the command line? which PC: the Windows 10 or 7? thanks!! – Natiya – 2019-06-13T15:10:37.827
Normally that registry value gets auto-added after you accept once. It's strange. – user1686 – 2019-06-13T15:36:14.590
This command will work on almost the entire Windows family, where you can run
psexec
. You need administrative privileges, i.e. You must run the command prompt as an administrator. In fact, this is an alternative to the method of installing the key in the manual viaregedit
. – STTR – 2019-06-13T17:28:35.727