Note that there are some explanatory texts on larger screens.

plurals
  1. POset variable to cmd.exe
    primarykey
    data
    text
    <p>Greeting earthmen,</p> <p>Here is my question:</p> <p>How can I create a program which sets variable to current session of cmd.exe e.g.</p> <pre><code>c:\&gt; set myvar Environment variable myvar not defined c:\&gt;myexe.exe c:&gt;set myvar myvar=myvalue </code></pre> <p>The only similar topic that I've found is this -</p> <p><a href="https://stackoverflow.com/questions/774047/how-can-i-change-windows-shell-cmd-exe-environment-variables-from-c+c">How can I change Windows shell (cmd.exe) environment variables from C++?</a></p> <p>But I didn't get a single word from this:</p> <blockquote> <p>There is a way... Just inject your code into parent process and call SetEnvironmentVariableA inside cmd's process memory. After injecting just free the allocated memory.</p> </blockquote> <p>While C/C++ is not my "native" language I've felt myself completely lost when I've searched google with "c++ inject code" and etc... Is there an article where I can get more info about this.</p> <p>BTW now I'm using one a little bit stupid workaround.As the setting a variable to </p> <p>HKEY_CURRENT_USER\Environment</p> <p>and </p> <p>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment</p> <p>is comparatively easy I'm just recording similar variable to the registry:</p> <pre><code>load.temp.vars=set myvar1=myval1&amp;set myvar2=myval2&amp; .... </code></pre> <p>and then just call %load.temp.vars% and it will be executed as a command: </p> <pre><code>c:/&gt;%load.temp.vars% c:/&gt;set myvar1 myvar1=myval1 </code></pre> <p>It works fine bu it's not good enough for me :)</p> <p>Live long and prosper, \\//_</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload