Greeting earthmen,
Here is my question:
How can I create a program which sets variable to current session of cmd.exe e.g.
c:\> set myvar
Environment variable myvar not defined
c:\>myexe.exe
c:>set myvar
myvar=myvalue
The only similar topic that I've found is this -
But I didn't get a single word from this:
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.
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.
BTW now I'm using one a little bit stupid workaround.As the setting a variable to
HKEY_CURRENT_USER\Environment
and
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
is comparatively easy I'm just recording similar variable to the registry:
load.temp.vars=set myvar1=myval1&set myvar2=myval2& ....
and then just call %load.temp.vars% and it will be executed as a command:
c:/>%load.temp.vars%
c:/>set myvar1
myvar1=myval1
It works fine bu it's not good enough for me :)
Live long and prosper, \\//_