Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Environment Variable
I am automating an installer that doesn't have a silent install option. I start the qm portable executable from the command line. The installer updates the path variable. I need to run a command line program that now in the path. I am using RunConsole2 to run the program. It gives me a cant find a dll error. The problem goes away if I exit the command prompt, exit portable qm, restart the command prompt , then restart the portable qm. Anyway to get the updated path without restarting command prompt then portable qm.
Function ReloadEnvVar
Copy      Help
function! $var

;Gets environment variable var from registry and updates it in this process.

;var - environment variable name.

;When a process is starting, in most cases it receives a copy of environment variables of its parent process.
;The first process (Windows Explorer) reads them from registry. It seems that processes started by the main Windows Explorer process also receive values from registry, but not sure is it always true, may need to log off/on.
;When somebody changes a system environment variable, variables in currently running processes are not updated. Their child processes also will receive old values.
;This function updates the specified variable in this process (QM).
;Then processes started by RunConsole2() also will receive the updated value. Processes started by run() probably will still receive old values.
;More info: (How to propagate environment variables to the system).

;out GetEnvVar("test" _s)
;RunConsole2 "setx.exe test ''delete me'' /M" ;;set a system environment variable in registry for testing. /M is for all users, requires admin rights.
;ReloadEnvVar "test"
;out GetEnvVar("test" _s)
;RunConsole2 "$my qm$\function271.exe" ;;QM-created exe with this code: out GetEnvVar("test" _s)

if(!rget(_s var "Environment") and !rget(_s var "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" HKEY_LOCAL_MACHINE)) ret
ret SetEnvVar(var _s)

Forum Jump:

Users browsing this thread: 1 Guest(s)