title: change environment variable on remote Windows machine
body: <p>I'm trying to set an environment variable on a remote machine.</p>
  
  <pre><code>setx /s machine var value
  </code></pre>
  
  <p>doesn't work - it produces no output and doesn't do anything.</p>
  
  <pre><code>psexec \\machine setx var value
  </code></pre>
  
  <p>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</p>
  
  <pre><code>psexec \\machine cmd /c set
  </code></pre>
  
  <p>it is written correctly.</p>
  
  <p>I wrote a program called RefreshEnvironment.exe that basically does the following:</p>
  
  <pre><code>    SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
      (LPARAM) L"Environment", SMTO_ABORTIFHUNG,
      5000, &amp;dwReturnValue);
  </code></pre>
  
  <p>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</p>
  
  <pre><code>psexec \\machine RefreshEnvironment.exe
  </code></pre>
  
  <p>returns "Access is denied". I can only run it with explicitly writing the user and password:</p>
  
  <pre><code>psexec \\machine -user domain\username -p password RefreshEnvironment.exe
  </code></pre>
  
  <p>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.</p>
  
  <p>Any idea will be welcome.</p>