- NSIS Discussion
- Refresh Environment
Archive: Refresh Environment
jweinraub
5th July 2007 21:10 UTC
Refresh Environment
I am having issues registering a dll file that my installer includes. I rather not put everything in the sys32 folder, so in order to register it, it needs to be in the $instdir. However, I need to use addtopath function. It works 70% of the time. On some machines, it seems to refuse to refresh the environment until the system reboots. I rather not reboot the system, but it seems to be the only way to work on certain machines. So far, it seems to be more of an issue on brand new computers.
It's the SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000 function that seems not to work.
On my development machines, I do notice the delay when this occurs. On other machines, nothing happens. If I echo the %path% nothing happens, until i reboot the system.
Please advise where to go on this.
Thanks!
kichik
5th July 2007 21:13 UTC
The most common cause for this is that only Explorer refreshes its environment table when WM_WININICHANGE is sent. Any other running process and any other process that's launched from such a process will not get the new environment variable.
jweinraub
5th July 2007 21:16 UTC
How do I fix this? Or do I need to reboot? Is there a way for me to detect this, and if so, it will send a reboot flag, so it will ask the user to reboot. And when the computer is logged back in, it will finish the last steps, like a post install registering the dll I need registered?
kichik
5th July 2007 21:19 UTC
It's not something to be fixed, it's just a question of how you test this. Instead of having an open console window, running the installer from it and then testing %PATH% in that console window, open a new console window after the installer is finished.
jweinraub
5th July 2007 21:25 UTC
You mean run the setup from the CLI?
so:
echo %path%
C:\nsis\test\setup.exe
echo %path%
?
I ran the echo twice before/post but i just double clicked the icon for setup (not running through the IDE).
The problem persists. Though, I don't see it in path, if i go to the variables property window, i will see the path there, and it wont refresh it u nl;ess i click okay there, but that happens only 25% of the time when it does fail from the installer.
kichik
5th July 2007 21:33 UTC
No, not through CLI. That's exactly what you shouldn't do. If you keep the console window open, %PATH% won't update. When the installer finishes, open a new console window and test from there.
jweinraub
5th July 2007 21:44 UTC
Allright I ran the test again. When I ran the installer, after it was completed I went into the CLI, ran echo %path% and the path i needed was not there. I uninstalled the program, restarted the computer, reran the installer. Then I did echo again and it was there. i manually ran regsvr32 and it failed. I rebooted the computer again and it was successful.
This only happens on brand new machines. On my development machines, it works every time w/o reboot.
kichik
6th July 2007 10:07 UTC
The differences between the script and the control panel are:
- The control panel flushes the registry key before sending the message using RegFlushKey.
- The script uses a longer timeout of 5 seconds instead of 1 second.
- The control panel uses SMTO_ABORTIFHUNG.
- The control panel also calls winsta::WinStatationBroadcastSystemMessage for administrators, to update other logged on users. I haven't been able to call that function from the script yet.
The only thing that might actually a difference is the key flushing. Try adding that before calling the SendMessage but after modifying the registry.
!define HKEY_LOCAL_MACHINE 0x80000002
System::Call "advapi32::RegOpenKeyExA(i ${HKEY_LOCAL_MACHINE}, \
t 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', \
i 0, i ${KEY_QUERY_VALUE}, *i .r0)i.r1"
System::Call "advapi32::RegFlushKey(i r0)i.r1"
System::Call "advapi32::RegCloseKey(i r0)i.r1"
jweinraub
6th July 2007 14:15 UTC
Originally posted by kichik
The only thing that might actually a difference is the key flushing. Try adding that before calling the SendMessage but after modifying the registry.
Kichik,
The one only thing that has me confused here is I am using your AddToPath function. So do I add this into the nsh file? Or do I manually call it within my installer?
Section "MainSection" SEC01
SetDetailsPrint textonly
DetailPrint "Installing My Software..."
SetDetailsPrint none
SetOutPath "$INSTDIR"
Push $INSTDIR
Call AddToPath
; snip ....
kichik
6th July 2007 15:26 UTC
You must add it to the NSH if you have to call it before SendMessage and after the registry key is modified.
jweinraub
6th July 2007 15:48 UTC
So... something like this?
!ifndef _AddToPath_nsh
!define _AddToPath_nsh
!define HKEY_LOCAL_MACHINE 0x80000002
!verbose 3
; .... snip ...
AddToPath_NTdoIt:
WriteRegExpandStr ${WriteEnvStr_RegKey} "PATH" $0
System::Call "advapi32::RegOpenKeyExA(i ${HKEY_LOCAL_MACHINE}, \
t 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', \
i 0, i ${KEY_QUERY_VALUE}, *i .r0)i.r1"
System::Call "advapi32::RegFlushKey(i r0)i.r1"
System::Call "advapi32::RegCloseKey(i r0)i.r1"
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
I don't know if this is right. I am still confused where to put that snippit of code.
kichik
6th July 2007 15:53 UTC
Yes, exactly like that.
jweinraub
6th July 2007 17:13 UTC
So far on my two test systems I am 2 for 2!! תודה רבה
pgg1
11th January 2008 17:15 UTC
I may have the same problem, what is KEY_QUERY_VALUE defined as?
Could somebody please let me anyone know?
Regards
Paul
pgg1
11th January 2008 17:24 UTC
I think I have found it.
!define KEY_QUERY_VALUE 0x0001
jweinraub
20th June 2008 16:30 UTC
I am now getting warnings:
3 warnings:
unknown variable/constant "{KEY_QUERY_VALUE}" detected, ignoring (AddToPath.nsh:79)
uninstall function "un.RemoveFromEnvVar" not referenced - zeroing code (66-138) out
install function "AddToEnvVar" not referenced - zeroing code (70-119) out
Even though I did remove the EnVar parts I still get that saying its still there!
But the unknown var i don't get.
i am getting problems where it doesnt add it to the path at all, and times where i do. it seems to be random, though restarting the computer and installing again seems to solve it. any ideas?