Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Registry PATH change/update withOUT restart 1

Status
Not open for further replies.

subzero349

Technical User
Oct 21, 2003
16
0
0
CA
Hello,

I have code that will read a registry entry and write a registry entry. I use this code to read in the PATH registry entry and write some new paths to it. I am modifying the following registry entry:

"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\"

Like I said, I can add: "c:\directory\" to the path no problem, but It actually doesn't work (when I try and run an .exe from the command prompt) until I preform a restart. I cannot afford a restart.

I'm using Windows 2000 - if you right click on "my computer" and then click the "advanced" tab, and then click the "environment variables" tab and navigate to the "PATH" and make an addition there - and click ok, ok, the change happens immediately - NO restart required... I would like to do this using delphi... I have found ways to do this for the desktop wallpaper change immediatly, but not the PATH.

Any help would be greatly appreciated.

PS - When I run my delphi program the way it is now, I can than open up the "environment variables" dialog from the system properties box and I can find that the change is there... but I still have to click ok, ok, for it to work it's magic and actually register the change...

 
I've seen a solution somewhere, that involves sending a message like WM_SETTINGS_CHANGED, or similar, to all open windows (including Explorer) to notify them all (in a single message) of the change. The exact WM_... constant I don't recall, and I can't trace back at the moment, but that's the direction to search. It will look like the message you had to send for the wallpaper change I guess.

HTH
TonHu
 
Thank you for your suggestion... I will search for WM_... stuff...

Here is the example for wallpaper:

"SystemParametersInfo(SPI_SETDESKWALLPAPER,0,nil,SPIF_SENDWININICHANGE);"

This compiles fine, but I can't find an appropriate "SPI_SETPATH" in place of "SPI_SETDESKWALLPAPER"

 
I tried

"SendMessage( HWND_BROADCAST, WM_WININICHANGE,0, LongInt(cs1));"

AND

"SendMessage( HWND_BROADCAST,WM_SETTINGCHANGE,0, LongInt(cs1));"

WHERE cs1 is:
const
cs1 : pchar = 'Windows';

I'm using windows 2000. Both of these calls compile and cause no errors. But they don't update the path :(
 
MORE info:

If I use my delphi program to change the registry, than I ctrl+alt+del and open the task manager and "end task" explorer.exe and than run explorer.exe again the changes take affect!

So I just need to somehow update explorer. I don't think it would be a good idea for me to right code that kills explorer and reopens it??

Any suggestions? ideas?
 
Doing what you did is the same as reseting as far as the computer is concerned (well.... a bit different, but that doesn't concern us here). And no, it wouldn't be a good idea, some things don't come back right.
 
I found where I read the original posting, it's here:
The excerpt of what you would need is this:
Code:
You must specify the string "Environment" in LParam. In Delphi you'd do it
this way:

  SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
Integer(PChar('Environment')));
It was suggested by Jordan Russell, the author of (a.o.) InnoSetup, ("Inno Setup is a free installer for Windows programs. First introduced in 1997, Inno Setup today rivals and even surpasses many commercial installers in feature set and stability.") (I just would like more people to use InnoSetup [2thumbsup])

HTH
TonHu
 
Thank you so much TonHu... I knew it could be done!

I tested it and it works great!

I will also check out that InnoSetup... sounds cool!

You get a star!
 
Can anyone see any problems with the following PATH:

"%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\NMapWin\bin;C:\Program Files\cvsnt;C:\PROGRA~1\Borland\Delphi6\Bin"

Now when I try and run "edit.com" it can't find it :( I have to navigate to c:\%systemroot%\system32\ to get it...

This problem has been caused by my registry editing program... :(
 
Never mind,

The problem was I was setting the registry to a REG_SZ instead of REG_EXPAND_SZ

This caused win2k not to understand the "%Systemroot%"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top