(solved) How do I update explorer/windows with registry changes?

Get help with using AutoHotkey and its commands and hotkeys
SvenBent
Posts: 266
Joined: 09 Aug 2015, 01:34

(solved) How do I update explorer/windows with registry changes?

03 Mar 2016, 14:46

When I make some changes to explorer registry settings they don't go into effect until after a reboot. Same as if I do it with regedit.
But if i go into Control Panel\System and Security\System >> advanced systesm, >> advanced >> performance settings
and i click any of the options here, and apply them. Explorer blinks for a short moment and the changes are in effect.

How do i provoke the same "refresh blink" with autohotkey ?
Last edited by SvenBent on 05 Mar 2016, 03:22, edited 1 time in total.
Shadowpheonix
Posts: 1259
Joined: 16 Apr 2015, 09:41

Re: How do I update explorer/windows with registry changes?

03 Mar 2016, 15:30

Process, Close, Explorer.exe should do what you want.
User avatar
MilesAhead
Posts: 232
Joined: 03 Oct 2013, 09:44

Re: How do I update explorer/windows with registry changes?

03 Mar 2016, 21:08

As a less drastic measure you could try calling the EnvUpdate function a few times. Although if the changes do stuff like add Buttons to Explorer you may need to kill explorer.exe as suggested above. For some things it can save you from logging off and back on or rebooting.
"My plan is to ghostwrite my biography. Then hire another writer to put his
name on it and take the blame."

- MilesAhead
qwerty12
Posts: 468
Joined: 04 Mar 2016, 04:33
GitHub: qwerty12

Re: How do I update explorer/windows with registry changes?

04 Mar 2016, 04:48

Calling SHChangeNotify with SHCNE_ASSOCCHANGED may refresh Explorer. If what you're trying to change is listed here, calling SystemParametersInfo will let you change it for the current session.
Last edited by qwerty12 on 04 Mar 2016, 13:06, edited 1 time in total.
SvenBent
Posts: 266
Joined: 09 Aug 2015, 01:34

Re: How do I update explorer/windows with registry changes?

04 Mar 2016, 10:39

Shadowpheonix wrote:Process, Close, Explorer.exe should do what you want.
unfeasible as it will kill the users explorer windows and loses where he is currently navigating.
MilesAhead wrote:EnvUpdate
Thank you i'll try that one
its basically just timers for menu and animations etc etc in explorer/windows that gets changed. no new gui objects are created
I;ve been looking for an autohotkey for this but didn't find anything that sounded right. must have missed this one.

--update--
oh i see now its only for environment variables. does nothing for registry changes sadly :(
I tried anyway but it didn't work
qwerty12 wrote:Calling SHChangeNotify with SHCNE_ASSOCCHANGED may refresh Explorer. If what you're trying to change is listed on https://msdn.microsoft.com/en-us/librar ... s.85).aspx, calling SystemParametersInfo will let you change it for the current session.
i jsut reicieved the 404 following your link but ima try googling those
User avatar
MilesAhead
Posts: 232
Joined: 03 Oct 2013, 09:44

Re: How do I update explorer/windows with registry changes?

04 Mar 2016, 11:01

SvenBent wrote: oh i see now its only for environment variables. does nothing for registry changes sadly :(
I tried anyway but it didn't work
Did you try calling it 3 or 4 times with a Sleep inbetween? I haven't tried this one in AHK myself. I have a small AutoIt3 utility using the equivalent au3 function. It seems to flush the registry changes to disk. But I didn't use it for the purpose of updating Explorer. Just to avoid logging off after editing the registry.
Anyway, I call it like this in au3

Code: Select all

;beginning of program removed for brevity
Sleep(1000)
EnvUpdate()
Sleep(500)
EnvUpdate()
Sleep(500)
EnvUpdate()
"My plan is to ghostwrite my biography. Then hire another writer to put his
name on it and take the blame."

- MilesAhead
SvenBent
Posts: 266
Joined: 09 Aug 2015, 01:34

Re: How do I update explorer/windows with registry changes?

04 Mar 2016, 11:18

i tried just activating my ahk script 3 times maully but nothing got update from the registry write
ima try it your way
SvenBent
Posts: 266
Joined: 09 Aug 2015, 01:34

Re: How do I update explorer/windows with registry changes?

04 Mar 2016, 11:24

this is what i quickly tried to see if it worked

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetBatchLines -1

RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, MenuShowDelay, 20
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop\WindowMetrics, MinAnimate, 0

Sleep 1000 
EnvUpdate
Sleep 500 
EnvUpdate
Sleep 500 
EnvUpdate

sleep 9999 

Sleep 1000 
EnvUpdate
Sleep 500 
EnvUpdate
Sleep 500 
EnvUpdate


Sleep 1000 
EnvUpdate
Sleep 500 
EnvUpdate
Sleep 500 
EnvUpdate

sleep 9999 

Sleep 1000 
EnvUpdate
Sleep 500 
EnvUpdate
Sleep 500 
EnvUpdate

it did not :( i can see the registry get changed though but explorer/windows is not updating itself to reflect those changes
User avatar
MilesAhead
Posts: 232
Joined: 03 Oct 2013, 09:44

Re: How do I update explorer/windows with registry changes?

04 Mar 2016, 13:03

SvenBent wrote:this is what i quickly tried to see if it worked

( code snipped )
I see. Worth a try anyway. :)
"My plan is to ghostwrite my biography. Then hire another writer to put his
name on it and take the blame."

- MilesAhead
SvenBent
Posts: 266
Joined: 09 Aug 2015, 01:34

Re: How do I update explorer/windows with registry changes?

04 Mar 2016, 13:08

yeah better to have tried a nonworking solution quickly, than to ignore a working one forever.

i think qwerty12 was onto the right thing with this
https://msdn.microsoft.com/en-us/librar ... 85%29.aspx

my calldll skills are still pretty low with actually parameters to use so I'm trying to butcher this into work but no luck so far.
qwerty12
Posts: 468
Joined: 04 Mar 2016, 04:33
GitHub: qwerty12

Re: How do I update explorer/windows with registry changes?

04 Mar 2016, 13:40

SvenBent wrote: i jsut reicieved the 404 following your link but ima try googling those
My bad, I edited the post to correct it :-)

Looking at the AHK code you posted, it seems like both of those can be changed on the fly:

Code: Select all

SPIF_SENDCHANGE := 0x02 ; Let running applications know of the change

newMenuShowDelay := 20
SPI_SETMENUSHOWDELAY := 0x006B
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop, MenuShowDelay, %newMenuShowDelay%
DllCall("SystemParametersInfo", "UInt", SPI_SETMENUSHOWDELAY, "UInt", newMenuShowDelay, "Ptr", 0, "UInt", SPIF_SENDCHANGE)

newMinAnimate := 0 ; <- change
SPI_SETANIMATION := 0x0049
szANIMATIONINFO := 8 ; size of ANIMATIONINFO structure - same on 32-bit and 64-bit
RegWrite, REG_SZ, HKEY_CURRENT_USER, Control Panel\Desktop\WindowMetrics, MinAnimate, %newMinAnimate%
VarSetCapacity(ANIMATIONINFO, szANIMATIONINFO) ; allocate space for ANIMATIONINFO structure
NumPut(szANIMATIONINFO, ANIMATIONINFO,, "UInt") ; set cbSize member to size of structure
NumPut(newMinAnimate, ANIMATIONINFO, 4, "Int") ; set iMinAnimate member to the new desired value - anything non-zero here enables animation
DllCall("SystemParametersInfo", "UInt", SPI_SETANIMATION, "UInt", szANIMATIONINFO, "Ptr", &ANIMATIONINFO, "UInt", SPIF_SENDCHANGE)	
My DllCall skills aren't too great but this works on my system at least...
SvenBent
Posts: 266
Joined: 09 Aug 2015, 01:34

Re: How do I update explorer/windows with registry changes?

04 Mar 2016, 14:05

oohh TY a lot

i did look into those dll calls but ran into the same issues that I don't know how to properly pass my parameters. i really need to find a very easy simple step by step guide so i can "learn to fish"
SvenBent
Posts: 266
Joined: 09 Aug 2015, 01:34

Re: How do I update explorer/windows with registry changes?

04 Mar 2016, 14:25

Quickfeedback.

The minanimate worked perfectly. ive tried messing around to not make the calls with variables but instead by hardcoded value, just to see if i could get a better grasp at the call ( i failed) but your code works perfectly flipping animation on/off without needing to reboot.

however he menu dely had no effect i tried with a value of 2000 20 1 and 0 and the many delay was still the same.
qwerty12
Posts: 468
Joined: 04 Mar 2016, 04:33
GitHub: qwerty12

Re: How do I update explorer/windows with registry changes?

04 Mar 2016, 15:41

SvenBent wrote:i did look into those dll calls but ran into the same issues that I don't know how to properly pass my parameters. i really need to find a very easy simple step by step guide so i can "learn to fish"
I'm not an expert in the slightest and there are undoubtedly far better people on this forum to tell you, but here's how I got the above. This is also probably littered with inaccuracies because of my limited knowledge... I do have Visual Studio installed, which is just as well; I use sizeof and offsetof a lot - when it comes to calculating structures' sizes, in the rare case I do get the arithmetic right, there's things I forget to account for like extra padding between structures, bumping up the size... This also isn't a generic guide applicable for all DllCall invocations because of what I've left out. I apologise in advance for how bad this post will be. My explanation skills leave a lot to be desired.

The SPIF_SENDCHANGE value I pulled directly from the Winuser.h header file (the header file containing the definition of the SystemParametersInfo function is in a table at the bottom of the page)
newMenuShowDelay comes from you.
Same with RegWrite, but I did make the change at the end to pull it from the newMenuShowDelay variable. I wrapped it in percent signs because I think they're required when referencing a variable in a function call that doesn't use brackets (think IfWinExist/IfWinNotExist vs. WinExist()) . https://autohotkey.com/docs/Variables.htm lists the proper rules, in any case.
Regarding the first DllCall:
  • First parameter is the function to be called, which in this case is SystemParametersInfo. As per https://autohotkey.com/docs/commands/DllCall.htm, I've left out the DLL name because SPI is from USER32.dll (as noted in the table on the bottom of the SPI page)
  • Second parameter is the type of the first argument. You can see the types the SPI function takes right at the top of the SPI page: UINT, PVOID etc. The valid types as accepted by the DllCall function are listed on its page. UINT maps to UInt.
  • Third parameter is the actual thing to set - which in this case is SPI_SETMENUSHOWDELAY. I pulled the value for that from the SPI page.
  • Fourth: same as the second point
  • Fifth: for SPI_SETMENUSHOWDELAY, this parameter (uiParam) is the new value of the setting. As you saw with the call to change the animation, its meaning changes depending on the value of uiAction. If you search for the uiAction value on the SPI page, it'll say what uiAction is used for in relation to it
  • Sixth (pvParam): same as the second parameter, but the type here is "Ptr". PVOID is another way of saying "void *" in Win32API parlance. I'm not really smart enough to eloquently explain what a pointer is :/
  • Seventh: SPI_SETMENUSHOWDELAY doesn't require anything here - pass a pointer that doesn't point to anything by sending 0
  • Eighth: same as the second point
  • Ninth (fWinIni): the SPI page explains this one, pretty much. I just figured sending SPIF_SENDCHANGE was a good idea
The animation one works differently. The description for it on the SPI page says that the pvParam parameter will be used this time and the uiParam parameter is not for setting the new value, but rather for the size of whatever we will pass in the pvParam parameter. The page says we're going to need to pass an ANIMATIONINFO struct. Since we can't directly reference a structure as defined in the Windows header files, we must redefine it so that AutoHotkey can recreate it.

I chose to find the size first (I cheated here and used Visual Studio, but...). Looking at the ANIMATIONINFO structure, it consists simply of two members: first an unsigned integer, and second and finally, a (signed) integer. https://msdn.microsoft.com/en-gb/library/s3f49ktz.aspx says the size for the unsigned integer is 4 bytes and the size of the (signed) integer is also 4 bytes, giving us a size of 8 bytes. Essentially, a struct groups various and/or same types of variables together in memory and the size of a struct is the size of all of its members (with maybe a bit extra if the compiler decides to add padding for optimisation).

I call on VarSetCapacity to set aside a contiguous space in memory to hold what will be our structure. First parameter is the variable name that will be used to reference this structure in function calls etc. - I unimaginatively chose ANIMATIONINFO and the second parameter is how large to make this chunk of memory - we already know we need 8 bytes to have enough space to be able to successfully populate an ANIMATIONINFO structure.

This results in us being granted our 8 bytes. Right now, it is not an ANIMATIONINFO structure. It's just a chunk of memory filled with random data probably. We can set values inside this piece of memory that'll result in it being treated as a valid instance of an ANIMATIONINFO structure by whatever examines it.

First, we use NumPut to set a value where the SPI function would look for the cbSize member. This is easy: NumPut should set the value of the szANIMATIONINFO variable (8) in the memory the ANIMATIONINFO variable is referencing, which we created with VarSetCapacity earlier. The Offset parameter is skipped because cbSize is the first member and it's at the beginning of the ANIMATIONINFO structure. "UInt" is at the end as that's the type of the cbSize member.

Next invocation of NumPut is pretty much the same, 'cept the Offset is now 4 - the cbSize member, an unsigned integer, takes four bytes of space - those four bytes need to be skipped from the beginning of the structure in order to get to the iMinAnimate member. The type of iMinAnimate is int so reflect that here.

The DllCall is mostly the same as the last but with these changes:
  • SPI_SETANIMATION stipulates uiParam must be the size of the ANIMATIONINFO structure so we pass szANIMATIONINFO again
  • For pvParam, a NULL pointer is not passed, but rather a pointer to our newly created ANIMATIONINFO structure instead. You'll note the use of the address-of (&) operator. This allows the SystemParametersInfo function to examine the structure created by us in AHK directly instead of being passed its own, unique copy (which wouldn't work anyway since it's expecting that pointer and not initially a raw chunk of memory).
SvenBent wrote:Quickfeedback.

The minanimate worked perfectly. ive tried messing around to not make the calls with variables by hardcoed value, just to see if i could get a better crasp at the call ( i failed) but your code works perfectly flipping animation on/off without needing to reboot.

however he menu dely had no effect i tried with a value of 2000 20 1 and 0 and the many delay was still the same.
From the SPI page, SPI_SETMENUSHOWDELAY affects the time it takes to show a submenu - I think that's what the Registry key affects, too. In any case, it did work here: I tried with a large time like 6000 and without logging out, my laptop took its sweet time showing the menu when I had my mouse hovered over a submenu... I could be wrong, though - maybe my Ctrl+F skills could do with improving :)
SvenBent
Posts: 266
Joined: 09 Aug 2015, 01:34

Re: How do I update explorer/windows with registry changes?

05 Mar 2016, 00:05

Thanks for all the help and explanation it was a huge help forward.

also you where right the menudelay thing did works it was just under a wrong assumption it would help with all menus and not just submenu's.
So now I'm trying to figure out which one disable the menu entirely. and wit your guide should be able to do it myself WOOT :dance:
SvenBent
Posts: 266
Joined: 09 Aug 2015, 01:34

Re: How do I update explorer/windows with registry changes?

05 Mar 2016, 00:19

ok jsut to verify how good/bad i did this

soo i found the actualy menu animation call "SPI_SETMENUANIMATION" aka 0x1003, i saw it did use the uiparam so i left that at uint 0 it used pvparam as boolean.
That had my confussed a little as autohotkey does not have abollean value i instead used char since it was one bytes as well.
and finnaly came up with this call

DllCall("SystemParametersInfo", "UInt", 0x1003, "Uint", 0, "Char", 0, "UInt", 0x00)

and it worked woohoot and yes i set fWinIni to 0x00 cause idont wnat to update the user profile as this is for a temporary use.

so thanks again. got my on the right path for dllcalls
SvenBent
Posts: 266
Joined: 09 Aug 2015, 01:34

Re: (solved) How do I update explorer/windows with registry changes?

05 Mar 2016, 18:21

I know i've marked this as solved but i ran into anothe obstacle

i figured out how to make the dllcalls for reading the current values from the guide above btu im struggling with the one for SPI_GETANIMATION. i simply cant figure out how to set up the stupid structure
qwerty12
Posts: 468
Joined: 04 Mar 2016, 04:33
GitHub: qwerty12

Re: How do I update explorer/windows with registry changes?

06 Mar 2016, 05:32

Awesome! Glad you figured out the call!
SvenBent wrote:That had my confussed a little as autohotkey does not have abollean value i instead used char since it was one bytes as well.
From the DllCall page:
An Int should also be used for each BOOL argument expected by a function (a BOOL value should be either 1 or 0).
and it worked woohoot and yes i set fWinIni to 0x00 cause idont wnat to update the user profile as this is for a temporary use.
Remember that there's the presence of the SPIF_SENDCHANGE flag, too. Leaving that flag out probably doesn't matter, but, say, if an application decides to draw its own menus etc. instead of letting Windows do it, and they listen for that message, having Windows send it will let those applications know of the change and they can also act accordingly.
i figured out how to make the dllcalls for reading the current values from the guide above btu im struggling with the one for SPI_GETANIMATION. i simply cant figure out how to set up the stupid structure
Check my post with the AutoHotkey code again. ;) There was already code there to set up an ANIMATIONINFO structure so that SPI_SETANIMATION can use it. Exactly the same thing, except:
  • Obviously, we need to use the value of SPI_GETANIMATION instead of SPI_SETANIMATION
  • cbSize must still be set (so we need the first NumPut), but since we're retrieving the value, we remove the NumPut call to set iMinAnimate
  • Yeah, there's no point in setting any flags for a get operation
  • We use NumGet to retrieve the value SPI set in the structure

Code: Select all

SPI_GETANIMATION := 0x0048
szANIMATIONINFO := 8 ; size of ANIMATIONINFO structure - same on 32-bit and 64-bit
VarSetCapacity(ANIMATIONINFO, szANIMATIONINFO) ; allocate space for ANIMATIONINFO structure
NumPut(szANIMATIONINFO, ANIMATIONINFO,, "UInt") ; set cbSize member to size of structure
DllCall("SystemParametersInfo", "UInt", SPI_GETANIMATION, "UInt", szANIMATIONINFO, "Ptr", &ANIMATIONINFO, "UInt", 0)	
MsgBox % NumGet(ANIMATIONINFO, 4, "Int")
For the NumGet call, why 4 is there is explained in my previous post
SvenBent
Posts: 266
Joined: 09 Aug 2015, 01:34

Re: (solved) How do I update explorer/windows with registry changes?

08 Mar 2016, 17:21

TY again for the help i will mess with it again once my food poisoning is over >.<

-- edit --
nah couldn't wait i implanted it and it worked flawlessly. TY

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot] and 204 guests