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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to change desktop 1

Status
Not open for further replies.

Alexial

Programmer
Nov 26, 2008
36
US
I've been working at this for a little while, and I would like to be able the change my desktop according to what day of the week it is. Right now I am getting a 'Wrong number of arguments or invalid property assignments: 'weekday'' at line 14, character 1:

Code:
set day = weekday

Here is the whole script:

Code:
'##########################################################
'#Writen by 
'#Changes desktop wallpaper according to the day of the week.
'##########################################################

dim wshShell
dim sUserName

Set wshShell = WScript.CreateObject("WScript.Shell")
sUserName = wshShell.ExpandEnvironmentStrings("%USERNAME%")

Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
set day = weekday

'##########################################################
'#Create an else case to determine day of the week
'#WeekdayName  1 = Sunday default start day of the week
'##########################################################

Select Case day
  case 1
    sWinDir = oFSO.GetSpecialFolder(0)
    sWallPaper = "C:\Documents and Settings\xxxx\My Documents\My Pictures\CharacterDesktops\xxxx.jpg"
    ' update in registry
    oShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", sWallPaper
    ' let the system know about the change
    oShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 1, True
  case 2
     sWinDir = oFSO.GetSpecialFolder(0)
    sWallPaper = "C:\Documents and Settings\xxxx\My Documents\My Pictures\CharacterDesktops\xxxx.jpg"
    ' update in registry
    oShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", sWallPaper
    ' let the system know about the change
    oShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 1, True
  case 3
    sWinDir = oFSO.GetSpecialFolder(0)
    sWallPaper = "C:\Documents and Settings\xxxx\My Documents\My Pictures\CharacterDesktops\xxxx.jpg"
    ' update in registry
    oShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", sWallPaper
    ' let the system know about the change
    oShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 1, True
  case 4
    sWinDir = oFSO.GetSpecialFolder(0)
    sWallPaper = "C:\Documents and Settings\xxxx\My Documents\My Pictures\CharacterDesktops\xxxx.jpg"
    ' update in registry
    oShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", sWallPaper
    ' let the system know about the change
    oShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 1, True
  case 5
    sWinDir = oFSO.GetSpecialFolder(0)
    sWallPaper = "C:\Documents and Settings\xxxx\My Documents\My Pictures\CharacterDesktops\xxxx.jpg"
    ' update in registry
    oShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", sWallPaper
    ' let the system know about the change
    oShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 1, True
  case 6
    sWinDir = oFSO.GetSpecialFolder(0)
    sWallPaper = "C:\Documents and Settings\xxxx\My Documents\My Pictures\CharacterDesktops\xxxx.jpg"
    ' update in registry
    oShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", sWallPaper
    ' let the system know about the change
    oShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 1, True
  case else
    sWinDir = oFSO.GetSpecialFolder(0)
    sWallPaper = "C:\Documents and Settings\xxxx\My Documents\My Pictures\CharacterDesktops\xxxx.jpg"
    ' update in registry
    oShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", sWallPaper
    ' let the system know about the change
    oShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 1, True
end select
wscript.quit

If anyone has any ideas or suggestions I'd appreciate the input! This is for my local computer, so there is no security hazards of any kind. Obviously all the images are different, I just used the xxxx.jpg for testing purposes.

Thank you!
 
Replace this:
set day = weekday
with this:
day = Weekday(Date)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Nope, still an error on line 14, character 1. Now it says:

Illegal assignment: 'day'

:( I had tried it before and got the same result, but I thought maybe the syntax was incorrect- still no go.
 
The word Day is a reserved word. Change your variable to a different name such as MyDay.

Code:
MyDay = Weekday(Date)

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Or you can put up a dimension statement on day.
[tt] dim day[/tt]
The downside is you would have troubled if you need somewhere else day built-in function. Hence, better to avoid naming variable as day or any reserved word for that matter.
 
Cool! Thanks for the help. I thought that was a reserved word, and had changed it at one point, but maybe I happened to change it to another reserved word ;)

I'll give it a try later this afternoon since the script is on my PC at home and I'm at work now. I'll let you know!
 
Ok! So, sorry it took so long to get back to you. Hopefully someone can help me out with this!

I got the code to work! I changed the 'Day' to 'Myday'(Thanks to Marc for the pointer!) but now for some reason my desktop appears as a solid color gray instead of the background.

When I go into the properties of my desktop however, it shows that it found the image file, and that it is indeed the current desktop, but doesn't seem to display. I'm not sure if maybe I'm writing something to the registry wrong? Maybe someone can help?

The code is the same as above (just make 'Day' into 'Myday') so I don't really think I need to re-post.

Thanks so much again!
 
Are you directing it to use a BMP file or a JPG? Try using a BMP.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Yep, I was using jpgs. I'll convert them into bmps and try that tonight. They would be HUGE though- they're pretty high quality and large resolution (1440x1050 at 400 DPI) would the size of the file make a difference?

Anyhow, I'll try that once I get home- back at work once again :)

Thanks for the idea!
 
Awesome! Converting the Jpg files to Bmp files worked like a charm! They're a bit big, but oh well :) Thank so much! You're the best man!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top