0

I'm trying to set an environment variable on a remote machine.

setx /s machine var value

doesn't work - it produces no output and doesn't do anything.

psexec \\machine setx var value

says it changed the value successfully. However when I go to the machine and open cmd, it doesn't show it. It does appear in the computer->properties->advanced->environment variables. Also, when I run

psexec \\machine cmd /c set

it is written correctly.

I wrote a program called RefreshEnvironment.exe that basically does the following:

    SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
    (LPARAM) L"Environment", SMTO_ABORTIFHUNG,
    5000, &dwReturnValue);

If I call it on local machine, it fixes the problem - I open cmd after it and get the correct environment. However, it doesn't work remotely. Calling

psexec \\machine RefreshEnvironment.exe

returns "Access is denied". I can only run it with explicitly writing the user and password:

psexec \\machine -user domain\username -p password RefreshEnvironment.exe

Very strange since it is the same domain,username and password on both machines; and it doesn't work - didn't say anything, but I still can't see the environment on the local machine.

Any idea will be welcome.

4

1 に答える 1