system variable not set on remote machine by psexec

0

Need to set-up system variable on remote machine. Performing

psexec \\remote_machine cmd /c setx foo bar

got reply

Success: Entered value was saved
cmd exited on remote_machine with error code 0

But when new console window started on remote_machine and command

set foo

was entered, got reply

system variable foo not defined

what am I doing wrong?

Both machines running windows 7, no AD environment present

user2956477

Posted 2019-05-12T23:43:28.653

Reputation: 131

Answers

0

To set system variables add the parameter /m to the setx command and make sure the command is run with an administrative account.

psexec \\remote_machine cmd /c setx foo bar /m

If you don’t specify /m the variable is only set for the currently logged on user. In the case of using psexec it will be whatever user psexec is run as. If you subsequently log on to the computer with a different user account the variable will not be present.

Appleoddity

Posted 2019-05-12T23:43:28.653

Reputation: 9 360

Does not help, same situation with /m switch – user2956477 – 2019-05-13T10:17:10.610

@user2956477 Then you aren’t running with a user that has administrative access on the remote machine. I tried to explain that. You can try adding /s to the psexec command. How are you authenticating if these machines aren’t in a domain? – Appleoddity – 2019-05-13T11:47:01.117

Just tried to search windows registry for variable name 'foo' and it is writen in HKCU/Environment, but not displayed on newly created cmd.exe window by command 'set foo' – user2956477 – 2019-05-13T13:27:35.003

I am using same username with same password on both machines, thus no interactive authentication needed. – user2956477 – 2019-05-13T13:29:35.000

@user2956477 some of your posts are a bit misleading. You said you want to create a “system” environment variable. Those would not show up under HKCU but instead in HKLM. System variables are system wide, for all users. This the suggestion to add /m. It’s not clear what you want? Use echo %foo% if you want to see that variable. – Appleoddity – 2019-05-13T13:48:13.573

Trying to be more specify: Need to keep some data in a variable ACROSS windows scripts. Script one is started, write some data into variable and terminate. Script two is started read, data writen by script one, insert some another data and terminate. Script three is started, read data writen by scripts one and two, and terminated. Something like VERY SIMPLE database replacement. System variable means, not a script bases variable because this dying by script end. Need variables level which storing data in the registry instead of in the memory. Sorry for misleading..... – user2956477 – 2019-05-13T21:12:50.573