Sign in to follow this  
Followers 0
jpm

EnvUpdate()

18 posts in this topic

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? :)

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by MHz

Share this post


Link to post
Share on other sites

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") )

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

@Zedmin

Yes, your right. missed inserting a line. Thanks.

Reading good now. :">

Share this post


Link to post
Share on other sites

I use Win2k English here.

Result:

Share this post


Link to post
Share on other sites

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. :)

Share this post


Link to post
Share on other sites

#12 ·  Posted (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.  :D

<{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 by ZeDMIN

Share this post


Link to post
Share on other sites

Yes, so you just confirm what I said first

We need JON to state on that

Thanks

Share this post


Link to post
Share on other sites

@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?

:)

Share this post


Link to post
Share on other sites

#15 ·  Posted (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 by Valik

Share this post


Link to post
Share on other sites

example/test... change wallpaper in the registry, then envupdate()... does that update the desktop... I really dunno

Lar.

<{POST_SNAPBACK}>

Doesn't work on Win2k English.

Share this post


Link to post
Share on other sites

@Larry

I get no hello from your example. :)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0