Jump to content

Refresh Windows with new desktop setting w/ AutoIT


sshrum
 Share

Recommended Posts

This is more of a Windows XP-related question but I need AutoIT to do it. :">

I'm making changes to the registry in regards to desktop settings (wallpaper, colors, etc).

Once the changes are in place, the only way I've found to get Windows to use them is to log the user out and back in again.

However, if you make desktop changes thru the Windows Display control panel, when you hit Apply (or OK), you get the "Please wait" dialog while the desktop fades into black and white and then a short time later, the new settings are used.

What needs to be done to make the "Please wait"+new settings be used without having to log the user out? Possible?

TIA

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Link to comment
Share on other sites

What needs to be done to make the "Please wait"+new settings be used without having to log the user out?  Possible?

<{POST_SNAPBACK}>

Not the cleanest, but have you tried opening the Display Properties Control Panel and simulating the Apply button click? Likely there is a DLL call to force the apply button -- some poking around or a nice query in the win32 api newsgroup might find you something...

A WinWaitActive for Display Properties, followed by sending an alt-a keystroke sequence ought to work.

From http://vbnet.mvps.org/index.html?code/system/controlpnl.htm

command:  rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,3 
result:  displays the Settings tab selected
Edited by flyingboz

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Link to comment
Share on other sites

I'd like to know this, too, but is there a reason you need to make the changes immediately when a user is logged on?

Here's the best workaround I can come up with: The red-green-blue background color must be different from the existing color in order for changes to take effect. (You can use ControlGetText to ensure it's always different.) However, I don't know if this forces ALL settings to update--even if you changed their registry keys.

Tested on Windows XP Pro SP2 English:

$title = "Display Properties"
Opt("WinWaitDelay", 1);speed things up a bit
Run("control.exe desk.cpl")
WinWait($title)
; For some strange reason @SW_HIDE fails but @SW_MINIMIZE works
WinSetState($title,"",@SW_MINIMIZE)
ControlCommand($title, "", "SysTabControl321", "TabRight")
ControlClick($title, "", 30054)
Send("o");I could not get ControlSend to work for me....
WinWait("Color")
ControlSetText("Color","","Edit4", "128");Red
ControlSetText("Color","","Edit5", "0");Green
ControlSetText("Color","","Edit6", "0");Blue
ControlClick("Color","","OK")

ControlClick($title,"","OK")
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Not the cleanest, but have you tried opening the Display Properties Control Panel and simulating the Apply button click?

Even if you ControlEnable and ControlClick the Apply button, nothing happens unless you made a change in some setting.

Moreover, only the item you change appears to be affected. If you edit the registry keys for background color, that color will NOT update if you only change the screen saver timeout before simulating a click of the Apply button.....

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Not the cleanest, but have you tried opening the Display Properties Control Panel and simulating the Apply button click?

This is what I have done in the meantime...a lot more coding is needed but it works.

I'd love it if I can do the change "silently" by just editting the registry settings and then have the desktop update with the new settings.

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Link to comment
Share on other sites

I'd like to know this, too, but is there a reason you need to make the changes immediately when a user is logged on?

Well...no. I could have the user wait until their next login but I'm more of the instant-gratification sorta guy. This way the user doesn't freak when their desktop changes when I'm not there...

This is what I came up with:

FileCopy("support\desktop\memcare.bmp", @WindowsDir)
;RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "Wallpaper", "REG_SZ", @WindowsDir & "\memcare.bmp")
;RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "WallpaperStyle", "REG_SZ", "0")
;RegWrite("HKEY_CURRENT_USER\Control Panel\Colors", "Background", "REG_SZ", "102 154 202")
Run("control.exe desk.cpl")
WinWaitActive("Display Properties")
Send("{TAB}{TAB}{TAB}{TAB}{RIGHT}!b")
WinWaitActive("Browse")
Send(@WindowsDir & "\memcare.bmp{ENTER}")
ControlClick("Display Properties", "", "Combobox1")
WinWaitActive("Display Properties")
Send("{UP}{UP}{UP}")
ControlClick("Display Properties", "", "Button2")
Send("!o!r102{TAB}154{TAB}202{ENTER}{ENTER}")
Edited by sshrum

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Link to comment
Share on other sites

SystemParametersInfo()

I don't see anything there that implies that DllCall() couldn't handle a whole bevy of problems!

This should work from the command line :

rundll32 user32.dll,UpdatePerUserSystemParameters

If that tests good, just RunWait() the above.

NOTE: Tested on XP home sp2 ENGLISH , works great!

:lmao:o:):)

Edited by flyingboz

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Link to comment
Share on other sites

This is what I tried:

FileCopy("support\desktop\memcare.bmp", @WindowsDir)
RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "Wallpaper", "REG_SZ", @WindowsDir & "\memcare.bmp")
RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "WallpaperStyle", "REG_SZ", "0")
RegWrite("HKEY_CURRENT_USER\Control Panel\Colors", "Background", "REG_SZ", "102 154 202")
RunWait("rundll32 user32.dll,UpdatePerUserSystemParameters")

The line you suggested doesn't seem to do anything. Even if I try to run the command directly after the registry edits, I see no changes to the desktop.

I'm on XP Pro SP2 English.

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Link to comment
Share on other sites

This works fine here, cut and pasted exactly from script...using latest "gold" copy of au3.

$img = @WindowsDir & '\Zapotec.bmp'
RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "Wallpaper", "REG_SZ", $img)
RunWait("rundll32 user32.dll,UpdatePerUserSystemParameters")

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Link to comment
Share on other sites

Nuts...that doesn't work for XP Pro.  The call is going through but the desktop is not updating. :lmao:

<{POST_SNAPBACK}>

This what I did on Win2K, haven't yet tested it on Win XP.

MouseClick("Left", 0, 0)

Send("{F5}")

It works, as long as the desktop is the active screen, sends the mouse pointer to the very top left of the desktop where there shouldn't be any shortcuts, then sends the Function 5 key (refresh)

Link to comment
Share on other sites

This what I did on Win2K, haven't yet tested it on Win XP.

MouseClick("Left", 0, 0)

Send("{F5}")

It works, as long as the desktop is the active screen, sends the mouse pointer to the very top left of the desktop where there shouldn't be any shortcuts, then sends the Function 5 key (refresh)

<{POST_SNAPBACK}>

*idea*

ControlSend('Program Manager', '', '', '{F5}')

Link to comment
Share on other sites

Bear in mind that F5'ing the desktop will not update the desktop background color changes if these changes have been made outside of the Display Properties control panel.

This is the primary source of my discontent

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Link to comment
Share on other sites

Works for me (XP Pro SP2) o:)  Thanks for pointing us to the right dll call at least :)

<{POST_SNAPBACK}>

Glad that it's working for somebody besides me -- It looks like there's a lot of sexy stuff in that call that could be accessed w/ DllCall - I only tested the wallpaper change - so I don't know what the real limits are.

:lmao: I wonder if it has something to do w/ being on a domain -- I tried it on a domain account w2k pro box, and there was no error, but also nothing happened -except a screen refresh- like what the original poster described when he tried my code snippet....

Edited by flyingboz

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Link to comment
Share on other sites

True...I am on a domain. 

<{POST_SNAPBACK}>

Still gotta be a way to skin this cat for virtually all o/s/config possibilities...Here's a code snippet people can try from their machines to see if they get any joy -Two data points is still pretty much a guess as far as I'm concerned. I'm going to take a peek at the docs and see what else I can find ...

The below is tested and working on a XPsp2 (home) PC. Replace the contents of $img1 and $img2 w/ bitmaps that are available on your system to test - this code will swap desktop wallpaper for current user between these two images - watch for wordwrap...

;Replace images with ones on your system - must be bitmaps.
$img1="c:\bat\spectrum.bmp" 
$img2="c:\bat\crop-colors.bmp"
;test current value of wallpaper
$wallpaper = RegRead("HKEY_CURRENT_USER\Control Panel\Desktop", "Wallpaper")
ConsoleWrite($wallpaper & @LF)
;make sure that we change wallpaper
If $wallpaper = $img1 then 
   RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "Wallpaper", "REG_SZ", $img2)
Else
   RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "Wallpaper", "REG_SZ", $img1)
EndIf

;force user update
$func="UpdatePerUserSystemParameters"
RunWait("c:\windows\system32\rundll32 USER32.DLL," & $func)

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Link to comment
Share on other sites

Well it's not a domain thing...I just tried this on my home PCs (XP PRO SP2 NO DOMAIN).

No errors but then again no update either. :lmao:

Here's my (evolving) code:

$img = "memcare.bmp" 
FileCopy("support\desktop\" & $img, @WindowsDir)

; THIS IS A REGWRITE (silent but requires user logoff/logon to work)
; RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "Wallpaper", "REG_SZ", @WindowsDir & "\" & $img)
; RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "WallpaperStyle", "REG_SZ", "0")
; RegWrite("HKEY_CURRENT_USER\Control Panel\Colors", "Background", "REG_SZ", "102 154 202")
; RunWait("rundll32 user32.dll,UpdatePerUserSystemParameters")

; THIS IS A GUI MIMIC (doesn't require logoff but not silent)
; Run("control.exe desk.cpl")
; WinWaitActive("Display Properties")
; Send("{TAB}{TAB}{TAB}{TAB}{RIGHT}!b")
; WinWaitActive("Browse")
; Send(@WindowsDir & "\" & $img & "{ENTER}")
; ControlClick("Display Properties", "", "Combobox1")
; WinWaitActive("Display Properties")
; Send("{UP}{UP}{UP}")
; ControlClick("Display Properties", "", "Button2")
; Send("!o!r102{TAB}154{TAB}202{ENTER}{ENTER}")

; BOZ IDEA (doesn't seem to do anything unfortunately)
$wallpaper = @WindowsDir & "\" & $img
$SPIF_SENDCHANGE = 2
$SPI_SETDESKWALLPAPER= 20
DllCall("user32.dll",'int',"SystemParametersInfo","int",$SPI_SETDESKWALLPAPER,"int",0,"str",$wallpaper,"int",$SPIF_SENDCHANGE)

Argh! I'm still willing to pound on this to make it run silent.

Edited by sshrum

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Link to comment
Share on other sites

  • 3 weeks later...

you can try something like this with the attached dll... can someone figure aut the right syntax?!

$result = DllCall("desktop.dll", "int", "d_paper", "hwnd", 0, ...

i used something like this with an NSIS installer i made a few years ago..work fine...

P.S.: I forgot where the dll came from, sorry...

P.P.S: Sorry, i can not attach the dpr file, so renamed it to txt, please rename to dpr

desktop.dll

desktop.txt

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...