jpm Posted September 29, 2004 Share Posted September 29, 2004 I try to figure out when this functions is needed without any success. I set the variable with EnvSet I don't needed it. If I write in the registry directly the current AutoIt Script cannot use it only the next run of a script will retrieve it. does somebody experience the same? Link to comment Share on other sites More sharing options...
MHz Posted September 29, 2004 Share Posted September 29, 2004 (edited) EnvSet is for changing the system environment variable within the script? A change without changing the values in registry. $var = EnvGet("allusersprofile") MsgBox(4096, "Path variable is:", $var) $var="" EnvSet("allusersprofile", "C:\") $var = EnvGet("allusersprofile") MsgBox(4096, "Path variable is:", $var) RegWrite("HKEY_CURRENT_USER\Environment", "TMP", "REG_EXPAND_SZ", "%USERPROFILE%\Local Settings\Temp") EnvUpdate() $ans=RegRead("HKEY_CURRENT_USER\Environment", "TMP") MsgBox(4096, "Path variable is:", $ans) While EnvUpdate would refresh the registry changes for a system environment variable. If I run this script without EnvUpdate after a change to TMP value. I get the old value. If I do use EnvUpdate, the change is recognized. EnvGet, EnvSet and EnvUpdate are working and do have their use. btw: I did change values in the regwrite for TMP. For testing script. Hope this helps you. Edited September 29, 2004 by MHz Link to comment Share on other sites More sharing options...
jpm Posted September 29, 2004 Author Share Posted September 29, 2004 I don't think your example is proving anything you can remove the EnvUpdate() and you yet the same result. I modify a little bit your code to show that is is not working in the same script as I mention. Thanks for trying to help me. I hope one of the AutoIT3 developper can clarify my concern :"> $var = EnvGet("allusersprofile") MsgBox(4096, "Path variable is:", $var) $var="" EnvSet("allusersprofile", "C:\") $var = EnvGet("allusersprofile") MsgBox(4096, "Path variable is:", $var) RegWrite("HKEY_CURRENT_USER\Environment", "TMP1", "REG_EXPAND_SZ", "test") EnvUpdate() $ans=RegRead("HKEY_CURRENT_USER\Environment", "TMP1") MsgBox(4096, "Path variable is:", EnvGet("tmp1") ) Link to comment Share on other sites More sharing options...
ZeDMIN Posted September 29, 2004 Share Posted September 29, 2004 Hiya, i agree with jpm, i can't see the use of EnvUpdate(). I tried some test-code and there was no difference if i used it or not. BUT: I recognized that things which are written in Registry won't be seen by EnvGet and vice versa. Or aren't they related? I have to add that i'm running on WinNT, can someone check it on Win2K / WinXP? Here's my code: $key1 = 'My_Test1' $key2 = 'My_Test2' If EnvGet($key1)='' Then EnvSet($key1, 'Content1') EndIf If RegRead("HKEY_CURRENT_USER\Environment", $key2)='' Then RegWrite("HKEY_CURRENT_USER\Environment", $key2, "REG_EXPAND_SZ", "Content2") EndIf ;EnvUpdate() MsgBox(4096, '', $key1 & " variable is:" & @LF & EnvGet($key1) & ' with EnvGet' & @LF & RegRead("HKEY_CURRENT_USER\Environment", $key1) & ' with RegRead') MsgBox(4096, '', $key2 & " variable is:" & @LF & EnvGet($key2) & ' with EnvGet' & @LF & RegRead("HKEY_CURRENT_USER\Environment", $key2) & ' with RegRead') I hope i was helpful Greetings, ZeD Link to comment Share on other sites More sharing options...
MHz Posted September 29, 2004 Share Posted September 29, 2004 It started working for me without EnvUpdate while testing it again. Now it is failing to refresh the change. Here is what I using now. $var = EnvGet("allusersprofile") MsgBox(4096, "Path variable is:", $var) $var="" EnvSet("allusersprofile", "C:\") $var = EnvGet("allusersprofile") MsgBox(4096, "Path variable is:", $var) RegWrite("HKEY_CURRENT_USER\Environment", "TMP", "REG_EXPAND_SZ", "%USERPROFILE%\Local Settings\Tempo") $ans=RegRead("HKEY_CURRENT_USER\Environment", "TMP") MsgBox(4096, "Path variable should be %USERPROFILE%\Local Settings\TempChange:", "EndUpdate off " & $ans) ;~ EnvUpdate() $ans=RegRead("HKEY_CURRENT_USER\Environment", "TMP") MsgBox(4096, "Path variable should be %USERPROFILE%\Local Settings\TempChange:", "EndUpdate On " & $ans) RegWrite("HKEY_CURRENT_USER\Environment", "TMP", "REG_EXPAND_SZ", "%USERPROFILE%\Local Settings\Temp") ;~ EnvUpdate() MsgBox(4096, "Path variable should be %USERPROFILE%\Local Settings\TempChange:", "EndUpdate On " & $ans) I am getting Tempo as the result in every message box, whem the last one should be Temp. Link to comment Share on other sites More sharing options...
jpm Posted September 29, 2004 Author Share Posted September 29, 2004 Hiya,i agree with jpm, i can't see the use of EnvUpdate(). I tried some test-code and there was no difference if i used it or not.BUT: I recognized that things which are written in Registry won't be seen by EnvGet and vice versa. Or aren't they related?I have to add that i'm running on WinNT, can someone check it on Win2K / WinXP?Here's my code:$key1 = 'My_Test1' $key2 = 'My_Test2' If EnvGet($key1)='' Then EnvSet($key1, 'Content1') EndIf If RegRead("HKEY_CURRENT_USER\Environment", $key2)='' Then RegWrite("HKEY_CURRENT_USER\Environment", $key2, "REG_EXPAND_SZ", "Content2") EndIf ;EnvUpdate() MsgBox(4096, '', $key1 & " variable is:" & @LF & EnvGet($key1) & ' with EnvGet' & @LF & RegRead("HKEY_CURRENT_USER\Environment", $key1) & ' with RegRead') MsgBox(4096, '', $key2 & " variable is:" & @LF & EnvGet($key2) & ' with EnvGet' & @LF & RegRead("HKEY_CURRENT_USER\Environment", $key2) & ' with RegRead')I hope i was helpful Greetings,ZeD<{POST_SNAPBACK}>I am running XP Link to comment Share on other sites More sharing options...
MHz Posted September 29, 2004 Share Posted September 29, 2004 XP here too Link to comment Share on other sites More sharing options...
ZeDMIN Posted September 29, 2004 Share Posted September 29, 2004 It started working for me without EnvUpdate while testing it again.Now it is failing to refresh the change.Here is what I using now.$var = EnvGet("allusersprofile") MsgBox(4096, "Path variable is:", $var) $var="" EnvSet("allusersprofile", "C:\") $var = EnvGet("allusersprofile") MsgBox(4096, "Path variable is:", $var) RegWrite("HKEY_CURRENT_USER\Environment", "TMP", "REG_EXPAND_SZ", "%USERPROFILE%\Local Settings\Tempo") $ans=RegRead("HKEY_CURRENT_USER\Environment", "TMP") MsgBox(4096, "Path variable should be %USERPROFILE%\Local Settings\TempChange:", "EndUpdate off " & $ans) ;~ EnvUpdate() $ans=RegRead("HKEY_CURRENT_USER\Environment", "TMP") MsgBox(4096, "Path variable should be %USERPROFILE%\Local Settings\TempChange:", "EndUpdate On " & $ans) RegWrite("HKEY_CURRENT_USER\Environment", "TMP", "REG_EXPAND_SZ", "%USERPROFILE%\Local Settings\Temp") ;~ EnvUpdate() MsgBox(4096, "Path variable should be %USERPROFILE%\Local Settings\TempChange:", "EndUpdate On " & $ans)I am getting Tempo as the result in every message box, whem the last one should be Temp.<{POST_SNAPBACK}>no, it shouldnt. you are reading the value into $ans BEFORE u are changing it ... Greetings,ZeD Link to comment Share on other sites More sharing options...
MHz Posted September 29, 2004 Share Posted September 29, 2004 @Zedmin Yes, your right. missed inserting a line. Thanks. Reading good now. :"> Link to comment Share on other sites More sharing options...
SlimShady Posted September 29, 2004 Share Posted September 29, 2004 I use Win2k English here. Result: Link to comment Share on other sites More sharing options...
MHz Posted September 29, 2004 Share Posted September 29, 2004 Hiya,i agree with jpm, i can't see the use of EnvUpdate(). I tried some test-code and there was no difference if i used it or not.BUT: I recognized that things which are written in Registry won't be seen by EnvGet and vice versa. Or aren't they related?I have to add that i'm running on WinNT, can someone check it on Win2K / WinXP?Here's my code:$key1 = 'My_Test1' $key2 = 'My_Test2' If EnvGet($key1)='' Then EnvSet($key1, 'Content1') EndIf If RegRead("HKEY_CURRENT_USER\Environment", $key2)='' Then RegWrite("HKEY_CURRENT_USER\Environment", $key2, "REG_EXPAND_SZ", "Content2") EndIf ;EnvUpdate() MsgBox(4096, '', $key1 & " variable is:" & @LF & EnvGet($key1) & ' with EnvGet' & @LF & RegRead("HKEY_CURRENT_USER\Environment", $key1) & ' with RegRead') MsgBox(4096, '', $key2 & " variable is:" & @LF & EnvGet($key2) & ' with EnvGet' & @LF & RegRead("HKEY_CURRENT_USER\Environment", $key2) & ' with RegRead')I hope i was helpful Greetings,ZeD<{POST_SNAPBACK}>This example does not change a registry key? It only creates one and reads from it. Test one is only EnvSet, which changes only in the script.EnvUpdate is about changing a value. Link to comment Share on other sites More sharing options...
ZeDMIN Posted September 29, 2004 Share Posted September 29, 2004 (edited) This example does not change a registry key? It only creates one and reads from it. Test one is only EnvSet, which changes only in the script.EnvUpdate is about changing a value. <{POST_SNAPBACK}>ummm, you're right, i supposed create=change I updated my test-code and came to following conclusions:- The EnvSet / EnvGet thingy is only usable by AutoIT and all programs it calls. (Looking in helpfiles is helpful sometimes )- The EnvUpdate() makes still no sense to me. Variables set with EnvSet() are immediately availiable for EnvGet() (or SET in a called command-shell) without using EnvUpdate(), RegWrites still aren't availiable with EnvGet() although i use EnvUpdate().- RegWrites aren't availiable from any program called by AutoIT (as Environmental Variable)!I hope everything is clear now Greetings,ZeD Edited September 29, 2004 by ZeDMIN Link to comment Share on other sites More sharing options...
jpm Posted September 29, 2004 Author Share Posted September 29, 2004 Yes, so you just confirm what I said first We need JON to state on that Thanks Link to comment Share on other sites More sharing options...
MHz Posted September 29, 2004 Share Posted September 29, 2004 @ZeDMIN Cool, we both mixed up with our examples. Seems EnvUpdate seems optional maybe for the concerned. If you have a script that may not getting the information refreshed correctly. Then insert EnvUpdate to make sure? Link to comment Share on other sites More sharing options...
Valik Posted September 29, 2004 Share Posted September 29, 2004 (edited) EnvUpdate() has absolutely nothing to do with EnvSet/EnvGet. EnvUpdate() broadcasts a WM_SETTINGCHANGE message. This informs any application that a setting somewhere in the system has changed. This could be the result of changing your display settings (Menu animation, font smoothing, whatever).Most applications ignore this message unless its lParam or wParam contains some information the application is interested in (An SPI_* message, a pointer to a registry key that changed, et cetera). EnvUpdate() just broadcasts a generic WM_SETTINGCHANGE message, so very few things will actually respond to it by reloading their settings.This may cause environment variables to be updated in the environment when writing to the registry. It depends on whether or not the thread responsibile for keeping the environment updated process a generic WM_SETTINGCHANGE message.Edit: Typos (Fixed, not added). Edited September 29, 2004 by Valik Link to comment Share on other sites More sharing options...
SlimShady Posted September 29, 2004 Share Posted September 29, 2004 example/test... change wallpaper in the registry, then envupdate()... does that update the desktop... I really dunnoLar.<{POST_SNAPBACK}>Doesn't work on Win2k English. Link to comment Share on other sites More sharing options...
MHz Posted September 29, 2004 Share Posted September 29, 2004 @Larry I get no hello from your example. Link to comment Share on other sites More sharing options...
jpm Posted September 29, 2004 Author Share Posted September 29, 2004 EnvUpdate() has absolutely nothing to do with EnvSet/EnvGet. EnvUpdate() broadcasts a WM_SETTINGCHANGE message. This informs any application that a setting somewhere in the system has changed. This could be the result of changing your display settings (Menu animation, font smoothing, whatever).Most applications ignore this message unless its lParam or wParam contains some information the application is interested in (An SPI_* message, a pointer to a registry key that changed, et cetera). EnvUpdate() just broadcasts a generic WM_SETTINGCHANGE message, so very few things will actually respond to it by reloading their settings.This may cause environment variables to be updated in the environment when writing to the registry. It depends on whether or not the thread responsibile for keeping the environment updated process a generic WM_SETTINGCHANGE message.Edit: Typos (Fixed, not added).<{POST_SNAPBACK}>so it could be good to change the doc to say what happening with the AutoIt implementation. From what I understand the next Autoit do not take care of env set by RegWrite. But as somebody has proces the WM_SETTINGCHANGE , the next execution will benefit of EnvUpdate()Thanks Valik 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