Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 1 Time in 1 Post

    VB to reset wallpaper? (Office XP SP-2)

    Allow me to concede up front that this is not a high priority difficulty I'm having...

    As I understand it, the code at the bottom of this post should change my wallpaper. And it does, but not completely. If I run it and then go to the Desktop tab of Display Properties, I can see the new wallpaper image in the preview window (i.e., the Registry-writing line is working fine). But the new image doesn't actually show up on my Desktop unless I manually fiddle with the Position setting, which causes the Desktop to properly refresh.

    Anybody know why the UpdatePerUserSystemParameters line isn't updating my Desktop?
    <pre>Dim VBSShell As Object
    Set VBSShell = CreateObject("WScript.Shell")
    VBSShell.RegWrite "HKCUControl PanelDesktopWallpaper", strWallpaperName, "REG_SZ"
    VBSShell.Run _
    "%windir%System32RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", _
    1, True
    Set VBSShell = Nothing</pre>


  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: VB to reset wallpaper? (Office XP SP-2)

    What about SendKeys? <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Is the call to RUNDLL32 actually working? Can it return an error code? Can you test by making some other change?

  4. #3
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: VB to reset wallpaper? (Office XP SP-2)

    The VBSShell.Run line is returning 0 -- which, if I'm reading the MSDN entry correctly, means no error.

  5. #4
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: VB to reset wallpaper? (Office XP SP-2)

    I should also mention that I've tried the API SystemParametersInfoA function, and it doesn't seem to be subject to the refresh glitch, but it only accepts bitmap files. The nice thing about the script approach is that it causes Windows to perform its behind-the-scenes conversion of a .jpg to a .bmp.

  6. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB to reset wallpaper? (Office XP SP-2)

    > I manually fiddle with the Position

    I found this too. I reset my wallpaper with a DOS batch file, same deal, although it is worse (for me) under Xp because I can't actually execute the autoexec.bat, so my "stuff" is two cycles late.

    I have VB6 code that resets the background colour and that takes effect immediately.
    <pre>Private Declare Function BlockInput Lib "user32" (ByVal fBlock As Long) As Long
    ' Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

    Private Declare Function SetSysColors Lib "user32" _
    (ByVal nChanges As Long, _
    lpSysColor As Long, _
    lpColorValues As Long) As Long

    Const COLOR_BACKGROUND = 1

    Public Sub Main()
    Call doit
    'wait 2 seconds before unblocking it
    ' Sleep 1000
    End Sub

    Private Sub doit()

    Dim retValue As Long
    Dim keyID As Long
    Dim bytHH As Byte
    Dim bytNN As Byte
    Dim bytSS As Byte
    '
    bytHH = 160 + (Format(Now(), "hh")) ' Hours as two digits
    ' bytHH = "00" ' seconds as two digits"
    bytNN = 160 + (Format(Now(), "nn")) ' Minutes as two digits
    ' bytNN = "00" ' seconds as two digits"
    bytSS = 160 + (Format(Now(), "ss")) ' seconds as two digits
    ' bytSS = "00" ' seconds as two digits"
    '
    retValue = SetSysColors(1, COLOR_BACKGROUND, RGB(bytHH, bytNN, bytSS))
    ' retValue = SetSysColors(1, COLOR_BACKGROUND, RGB(bytSS, bytNN, bytHH))
    '

    End Sub</pre>


  7. #6
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: VB to reset wallpaper? (Office XP SP-2)

    Thanks for the input. The fact that you used to use Autoexec.bat implies you're only looking for a once-a-boot wallpaper change. Maybe the XP solution for that is to put the code in a script that runs at shutdown (which I expect would cause the change to take full effect on the next startup).

  8. #7
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB to reset wallpaper? (Office XP SP-2)

    > put the code in a script that runs at shutdown
    Thanks, Steve

    (returns to drawing board)

  9. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: VB to reset wallpaper? (Office XP SP-2)

    I once used a utility called WinDowse to sniff the system messages and other messy internal communications of an application with Windows. Perhaps you can use something like that to ascertain whether the Display Properties control panel is secretly sending some other signal to Windows that you also could send?

  10. #9
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB to reset wallpaper? (Office XP SP-2)

    I spent (far too) much time trying to "solve" this problem. There does not seem to be anything avaialbe other than refreshing to the desktop. If you are just using VBScript, that means SendKeys and calling up the Desktop applet. The amount of time required for SendKeys to work means inevitable collisions with other keyboard activities.

    If you have VB6, you can cut down the SendKeys by setting references to shell32.dll & the Scripting Runtime and including the following:<pre>Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    ...other code here...
    ' Refresh the desktop to display the new image
    Set shl = New Shell
    shl.ToggleDesktop
    Sleep (750) ' Allow enough time for the SendKeys command to work
    wsh.SendKeys "{F5}"
    Sleep (250) ' Allow enough time for the SendKeys command to work
    shl.ToggleDesktop
    Set shl = Nothing
    Set wsh = Nothing</pre>

    Theoretically, you should be able to work up a less messy version using JavaScript and <code>document.writeIn()</code>.

    HTH
    Grüße

  11. #10
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: VB to reset wallpaper? (Office XP SP-2)

    Thanks very much for putting in the time. You've helped confirm me in my tentative conclusion that there's no straightforward solution. If by "VB6" you mean standalone VB, I don't have that (just Office XP Pro), and I wonder if your code would work for me in any case since manually executing the desktop Refresh command (either from the right-click menu or using F5) generally fails on my PC after I change the wallpaper with the code in my original post. (It's most likely to work after the very first time I run the code, perhaps because I'm taking over at that point from a WallpaperChanger program that uses a different path/name for the current wallpaper.)

  12. #11
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: VB to reset wallpaper? (Office XP SP-2)

    VB6 is not required to use Windows' Sleep function:
    <UL><LI>You can use the Sleep API in a VBA module by declaring it at the top (as illustrated above).
    <LI>You can use the Sleep procedure in VBScript at the command prompt in this form: WScript.Sleep(millisconds)[/list]SendKeys, of course, you know about.

    I'm not sure what ToggleDesktop is...

  13. #12
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: VB to reset wallpaper? (Office XP SP-2)

    I wondered about that. I tried adding a Reference to Shell32 but ToggleDesktop didn't show up in the Object Browser.

  14. #13
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB to reset wallpaper? (Office XP SP-2)

    > I tried adding a Reference to Shell32 but ToggleDesktop didn't show up in the Object Browser
    After setting the reference to Shell32, try <code>Dim shl As IShellDispatch4</code>. I should have included this in my initial post - as it took me a fair amount of digging to get to it.

    <img src=/S/sorry.gif border=0 alt=sorry width=15 height=15>Am only now catching up on backlog threads on this Board.

    HTH
    Grüße

  15. #14
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: VB to reset wallpaper? (Office XP SP-2)

    Thanks again for spending the time on this. Your .ToggleDesktop/SendKeys code doesn't work for me, but I assume that's because a manual Refresh (either using F5 or from the right-click menu) also doesn't work for me in that context. That is, if I run my 2 VBSShell lines (which clearly do enough for the new image to appear in the Desktop preview window), and then manually hit F5, the old image remains on my desktop.

  16. #15
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB to reset wallpaper? (Office XP SP-2)

    Other ideas:<UL><LI>Try deleting Cocuments and Settings[username]Application DataMicrosoftInternet ExplorerDesktop.htt at the top of the code<LI>Instead of rewriting the Registry Key, rewrite a CSS file linked to an HTML file that you've set as your wallpaper - works for me<LI>As a LAST resort, use Shell.Run to call up the Display applet and then use SendKeys to move the choice up & down 1 item (very messy)[/list]HTH
    Grüße

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •