Sign in to follow this  
Followers 0
hispeed_mike

Refresh Registry

16 posts in this topic

I have a registry key to write which needs to then refresh the registry so I can apply it without restarting windows....

I know I found it once before but forgot the dll I need to call and don't have time to sift throught the forums.

Thanks again in advance.

Havn't called these type of functions before so if you could give me a quick exapmle of code would be great...

Thanks

Mike

Share this post


Link to post
Share on other sites



You don't "Refresh" the registry. When you write something, it is there. Depending on the application(s) this registry key affects, there may or may not be a way to signal the application to re-check the registry.

If my answer is vague, it matches the question.

Share this post


Link to post
Share on other sites

You don't "Refresh" the registry. When you write something, it is there. Depending on the application(s) this registry key affects, there may or may not be a way to signal the application to re-check the registry.

If my answer is vague, it matches the question.

Thanks Valik,

I understand that once written the value is there and the program needs to check the registry. The problem is this is a windows explorer registry value namely:

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced]

"WebView"=dword:00000000

This regkey changes the Folder view in explorer. Normally you click apply after changing this option through the tools menu. This then applies the changes made to registry. Now I can change the value but it does not get applied until reboot when the registry gets reread by default.

I need to make this change to a heap of PC's used in a kiosk environment, hence the need to make registry change then force windows to read this change and apply...

Hope this helps. Any ideas?

Sorry for first question being so vague, I didn't want to bore anyone with details....My mistake.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

This is a Start Menu change correct?

This will refresh the start menu, but don't ask me how to convert it to AutoIT.

#define SM_REFRESH_START_MENU WM_APP + 67
...
HWND hwndStart = FindWindow( L"MSStart", NULL );

PostMessage(hwndStart, SM_REFRESH_START_MENU, 0, 0);
Edited by big_daddy

Share this post


Link to post
Share on other sites

Nevermind I found that it wasn't a Start Menu change. This code tells windows to update all settings and policies.

var c1 : dword;
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, integer(pchar('Policy')), SMTO_NORMAL or SMTO_ABORTIFHUNG, 5000, c1);

Share this post


Link to post
Share on other sites

This is one way:

While ProcessExists ( "explorer.exe" )

ProcessClose ( "explorer.exe" )

Wend

sleep(100)

Run("explorer.exe")

sleep(1000)

If NOT ProcessExists("explorer.exe") Then Run("explorer.exe")

This is a rather violent way to apply your settings though since it is ending explorer.exe. This however will force explorer to completely re-read everything from the registry. I don't know if this is what you were looking for.


"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

I have the same problem, and can't find anything else.

Restart Windows Explorer - it's working, but... it's really wrong.

It must be the way to refresh settings, because when we change settings through Explorer's GUI interface, they working immediatly. Probably, only professional programmers know this.

If somebody can help, please write here. At any time.

Thank you.

Share this post


Link to post
Share on other sites

I have the same problem, and can't find anything else.

Restart Windows Explorer - it's working, but... it's really wrong.

It must be the way to refresh settings, because when we change settings through Explorer's GUI interface, they working immediatly. Probably, only professional programmers know this.

If somebody can help, please write here. At any time.

Thank you.

http://weblogs.asp.net/whaggard/archive/2003/03/12/3729.aspx

or

http://www.nirsoft.net/utils/restart_explorer.html



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

Thanks, but i don't want to kill Explorer. I need to save all existing user's Explorer windows.

About Alt+Ctrl+Del - it's working sometimes and very strange. And is no good idea for automation.

I need something like a "system call" for Explorer. Will try to find.

Share this post


Link to post
Share on other sites

...

I have a registry key to write which needs to then refresh the registry so I can apply it without restarting windows....

I have the same problem, and can't find anything else.

Restart Windows Explorer - it's working, but... it's really wrong.

...

If somebody can help, please write here. At any time.

I'm late because it was a long search. Perhaps it still can help somebody.

#include <misc.au3>
_SendMessage(0xffff,0x1A,0,0)

Please ignore, if this problem was already solved somewhere else.

Share this post


Link to post
Share on other sites

I'm late because it was a long search. Perhaps it still can help somebody.

#include <misc.au3>
_SendMessage(0xffff,0x1A,0,0)

Please ignore, if this problem was already solved somewhere else.

Hi there - i just tried your _sendmessage - but it doesnt appear to do anything - in my situation im writing a registry entry to HKEY_CURRENT_USER\Environment

at the mo we are using kix scripts for login - but as they are getting bigger they are getting less reliable - so my idea was to use autoit - everything is sweet except for this registry entry - all its doing is adding a User PATH to the default machine path - this is the same place that KIX puts it so it doesnt overwrite any other path that has been set

any ideas on how to get this refresh to work ?

Share this post


Link to post
Share on other sites

Send("#r")
WinWait("Run")
WinActivate("Run")
WinWaitActive("Run")
Send('cmd /k echo %TMP%{ENTER}')
MsgBox(4096,"","Close DOS Window and click OK")

$a = RegRead("HKCU\Environment","TMP")
RegWrite("HKCU\Environment","TMP","REG_EXPAND_SZ","C:\Larry Rocks")
EnvUpdate()

Send("#r")
WinWait("Run")
WinActivate("Run")
WinWaitActive("Run")
Send('cmd /k echo %TMP%{ENTER}')
MsgBox(4096,"","Close DOS Window and click OK")

RegWrite("HKCU\Environment","TMP","REG_EXPAND_SZ",$a)
EnvUpdate()

Send("#r")
WinWait("Run")
WinActivate("Run")
WinWaitActive("Run")
Send('cmd /k echo %TMP%{ENTER}')
MsgBox(4096,"","Close DOS Window and click OK")

oh shit - i so over looked ENVUPDATE() - how stupid of me

thanks larry

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Is it necessary to add 'envupdate()' after each registry editing? Or just once after all the changes made?

It looks kind of redundant doesn't it?

Only if you changed System or User environment variables via the registry, which become the "DOS Shell" variables like %TEMP%. EnvUpdate() updates those shell variables in the shell that AutoIt is running in.

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

for example?

i mean...can a single 'EnvUpdate()' update all the editing done in one go?

Editing of what? The changes are effective in the registry as soon as they are made, and EnvUpdate() has nothing to do with that. In the special case of registry keys that are read to create the shell environment variables, one call to EnvUpdate is all that's required.

But there's no need to wonder about it. Test it. A demo script would be easy to code. Exactly what change are you interested in?

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

maybe to disable Net Crawling or lock IE's homepage to prevent homepage editing by spywares?

I'm actually curious about it because certain registry entries do not reflect their changes until rebooted.

Some IE changes require you to restart IE, but not a reboot of the whole machine. But it's still very easy to test... have you done your script to test it yet?

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

This is one way:

While ProcessExists ( "explorer.exe" )

ProcessClose ( "explorer.exe" )

Wend

sleep(100)

Run("explorer.exe")

sleep(1000)

If NOT ProcessExists("explorer.exe") Then Run("explorer.exe")

This is a rather violent way to apply your settings though since it is ending explorer.exe. This however will force explorer to completely re-read everything from the registry. I don't know if this is what you were looking for.

I have the same problem, and can't find anything else.

Restart Windows Explorer - it's working, but... it's really wrong.

It must be the way to refresh settings, because when we change settings through Explorer's GUI interface, they working immediatly. Probably, only professional programmers know this.

If somebody can help, please write here. At any time.

Thank you.

I agree with Shaggy. This is REALLY wrong. It would be my absolute last resort. I'm posting the solution so nobody else is tempted to try that kludge.

Fortunately, MS actually provides a routine for such updates. Look at http://msdn.microsoft.com/en-us/library/windows/desktop/bb762118(v=vs.85).aspx. As stated by MS, "An application should use this function if it performs an action that may affect the Shell."

After writing a new icon association to the registry, I call this function using the following line:

SHChangeNotify SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0&, 0&

(Function and constant declarations omitted from this example. See the MS reference.)

The icons are then refreshed for both the desktop and all instances of explorer.

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