rudi Posted April 25, 2008 Share Posted April 25, 2008 Hello, I'd like to set some environment variables from an autoit script. [helpfile] EnvUpdate -------------------------------------------------------------------------------- Refreshes the OS environment. EnvUpdate ( ) These settings shall be permanent for that PC: EnvSet("ChoppitPath","C:\Choppit\") RunWait (@ComSpec & " /k set | find /i ""Choppit""") EnvUpdate() ; opening a "Start, CMD" cmd box or looking to the Env Settings in the "System Properties" shows ; that the OS' Environment was *NOT* updated? MsgBox(0,"","done") What do I miss? Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
herewasplato Posted April 25, 2008 Share Posted April 25, 2008 ...What do I miss?..."EnvUpdate() has absolutely nothing to do with EnvSet/EnvGet."http://www.autoitscript.com/forum/index.ph...ost&p=33358"EnvUpdate() is irrelevant to causing environment variables to be updated unless writing the variables to the registry."http://www.autoitscript.com/forum/index.ph...st&p=108910Oddly enough, those were not the posts that I was looking for... but they may help you. [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Richard Robertson Posted April 25, 2008 Share Posted April 25, 2008 EnvUpdate sends a message to the system saying that system wide changes have been made. The environment variables can be different between processes. Each tree of processes has access to an "environment" if I remember correctly. Of course, I could be completely wrong. Link to comment Share on other sites More sharing options...
rudi Posted April 25, 2008 Author Share Posted April 25, 2008 (edited) Hi, thanks for your replies. I found a nice tool included in the XP SP2 Support Tools Pack: WindowsXP-KB838079-SupportTools-ENU.exe With SETX.EXE it's easy to change environment variables to the OS Environment SETX: This program is used to set values in the environment of the machine or currently logged on user using one of three modes. 1) Command Line Mode: setx variable value [-m] Optional Switches: -m Set value in the Machine environment. Default is User. 2) Registry Mode: setx variable -k hive\key\...\value Optional Switches: -m Set value in the Machine environment. Default is User. 3) File Mode: setx variable -f file {-a x,y | -r x,y "string"} [-d d] [-x] [-m] Required Switches: -f file : Specify file name to use. -a x,y : Specify absolute coordinates and offset. -r x,y "string" : Specify coordinates and offset relative to string. Optional Switches -d ,:\ etc. : Specify additional delimiters. -x : Displays file coordinates. Switches -a -r -e ignored!! -m : Set value in the Machine environment. Default is User. For more information and example use: SETX -i But EnvUpdate() seems not to work Dim $UserEnv=" FooUser" Dim $MachEnv=" FooMachine" Dim $MyVal=" sunshine" dim $setx ='"' &@ProgramFilesDir & '\Support Tools\setx.exe"' RunWait($setx & $UserEnv & $MyVal ) RunWait($setx & $MachEnv & $MyVal & " -m") EnvUpdate() MsgBox(0,"info","EnvUpdate() done...",2) MsgBox(48,"Does NOT work","And now you can see, that the new opened CMD box doesn't reflect the updated Env.") Run(@ComSpec & " /k set") MsgBox(0,"Environment *IS* updated","Now you can check, that the Machine Env Var """ & $MachEnv & """" & @LF & _ "and the User Env Var """& $UserEnv & """ *ARE* set ...") send("{LWINDOWN}{pause}{LWINUP}") Why? [hkcu\environment] and [HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment] both reflect the settings, EnvUpdate() should update these system wide, right? Regards, Rudi. Edited April 25, 2008 by rudi Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
rudi Posted April 28, 2008 Author Share Posted April 28, 2008 Bump: Still facing this trouble -- what do I miss? Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
MHz Posted April 28, 2008 Share Posted April 28, 2008 This is my understanding of Env...()EnvSet/EnvGetThe parent process inherits the environment at execution and any child process executed from the parent process inherits the same environment. You can use EnvSet() to alter the environment variables and create new environmental variables at a software level within the process and child processes of the parent process. You can use EnvGet() to retrieve the environmental variables inherited and by those set/modified by EnvSet(). EnvSet() does not do a permanent change to the environmental variables.EnvSet() changes at the software level and the child process of @ComSpec inherits the change below.EnvSet('ProgramFiles', 'C:\rudi') RunWait(@ComSpec & ' /k set ProgramFiles')oÝ÷ Ù±'½J]j׿m.q©î±ä^jâµëh©¥êæjw§µÈZ¬¶§¾*èg§µ©oj¸nW¬{az· ËkÉ»j|©àzÌ"Y趷ë!¶ø«¢yÖ¥½ªâi¹^²íç.®·§¶«z{i®²ËajØx^®+^u«lµªí¡÷±yËè©òr¥vèqë,zDZyËy×ë¢kaz«z{i®²Ãh®f¥&«zËZ®Ú¶J++z«¢ç_¢¶§Êw°¥ªÞÚk¡Ç¬²Ú"«ÛayÈZ¬¶ayéïº'éíjÊkzø¨ºÉrvÞ{Ô¥Öy©e£)j·§¶èqë,zDZyËyÖµêíë¬zÄõ)u«^¶§êâ¶Ø^z{â®æz{ZÈZ¬Â+a¢ëZë-j»h~Ø^9$è±çõ)u«^Â䶧ʧyçv¥ªÞÚk¡Ç¬±ë-¢×¬µ§¶¬jëh×6If RegRead('HKCU\Environment', 'test') = '' And @error Then RegWrite('HKCU\Environment', 'test', 'REG_SZ', 'string') EnvUpdate() MsgBox(0x40000, Default, 'Start a new process now') EndIfoÝ÷ ÚØ^^*.±çã,º1¶§®éí+ºÚ"µÍ[ØZ] ÛÛTÜXÈ [È ÌÎNÈÚÈÙ]Ý ÌÎNÊBYÑ[]J ÌÎNÒÐÕIÌLÑ[ÛY[ ÌÎNË ÌÎNÝÝ ÌÎNÊB[]JDo not run both of these scripts from the same instance of Scite as Scite will be the parent process and both scripts will execute as child processes so the environment change may not be seen to change. Start the scripts through explorer will do. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now