Computer Hope
Microsoft => Microsoft DOS => Topic started by: newkid on July 21, 2010, 02:08:11 AM
-
Hello,
I want to cycle thru a list of pictures in a directory and update my wallpaper each time i logon to windows
any ideas on the code I would need...then I assume I put this code in the startup
Thanks
Steve
-
I found this in the snippet closet which may help:
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
intLowNumber = 1
intHighNumber = 3 'Total Number Of Wallpaper Choices
intNumber = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
Select Case intNumber 'Case Statements LowNumber to HighNumber
Case 1 : strPicture = "fully qualified path to picture 1"
Case 2 : strPicture = "fully qualified path to picture 2"
Case 3 : strPicture = "fully qualified path to picture 3"
End Select
strKeyPath = "Control Panel\Desktop"
ValueName = "Wallpaper"
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strPicture
Set intHighNumber to the number of pictures you cycle through. The case statements are sequential from intLowNumber (which should be one) to intHighNumber. Set strPicture to the fully qualified path to each of your pictures.
The script will randomly select a picture each time it is run and update the registry. If you have a shutdown script, I would put it in there so the wallpaper resets at the next boot. If you put it in the startup folder, the wallpaper change may not take effect until you logoff/logon. You may have to play around with this.
Save the file with a VBS extension and run from within another script or from the command prompt as cscript scriptname.vbs
Good luck. 8)
-
thanks for that
what about if i wanted to do it in DOS
for example
get the oldest file in a directory
copy it to a target file that is being used for the wallpaper
change the source file so it becomes the newest file
cheers
-
First a correction. The VBScript has a missing statement. The corrected version is below:
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
intLowNumber = 1
intHighNumber = 3 'Total Number Of Wallpaper Choices
Randomize
intNumber = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
Select Case intNumber 'Case Statements LowNumber to HighNumber
Case 1 : strPicture = ""
Case 2 : strPicture = ""
Case 3 : strPicture = ""
End Select
strKeyPath = "Control Panel\Desktop"
ValueName = "Wallpaper"
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strPicture
Sorry for any confusion.
what about if i wanted to do it in DOS
First you would need a machine with DOS installed. Why do you want to use batch code anyway on a WinXP machine?
@echo off
set source="source directory goes here"
set dest="destination directory goes here"
for /f "tokens=* delims=" %%i in ('dir /ta /b /o:d %source%') do (
echo y | copy "%source%\%%i" "%dest%" > nul
echo Y | copy /b "%dest%\%%i" "%source%" > nul
echo y | reg add "HKCU\Control Panel\Desktop" /v Wallpaper /d "%dest%\%%i" > nul
goto :eof
)
Be sure to change source and dest to valid directory names otherwise its the same stuff as yesterday: The script will select a picture each time it is run and update the registry. If you have a shutdown script, I would put it in there so the wallpaper resets at the next boot. If you put it in the startup folder, the wallpaper change may not take effect until you logoff/logon. You may have to play around with this.
8)
-
hello,
Im a former Cobol programmer, so im learning as i go :).....so I dont have VB to develop in but I do know a little about dos...not much as you can see
if there is a way to develop in VB without having to pay for it ....i could do that ??
I tried the dos script but it gave me this
Source = "C:\path\input"
Dest = "C:\path\output"
copy ""C:\path\input"\pic1.jpg" ""C:\path\output""
and the copy didnt work
thanks for your help
cheers
-
Check out Microsofts Express range
http://www.microsoft.com/express/Windows/ (http://www.microsoft.com/express/Windows/)
Graham
-
Im a former Cobol programmer
You might like COBOL.NET (http://www.netcobol.com/products/Fujitsu-NetCOBOL-for-.NET/overview) :)
-
I guess I got a little carried away with the quotes.
@echo off
set source=source directory goes here
set dest=destination directory goes here
for /f "tokens=* delims=" %%i in ('dir /a:-d /ta /b /o:d "%source%"') do (
echo y | copy "%source%\%%i" "%dest%" > nul
echo Y | copy /b "%dest%\%%i" "%source%" > nul
echo y | reg add "HKCU\Control Panel\Desktop" /v Wallpaper /d "%dest%\%%i" > nul
goto :eof
)
Do not quote the source or dest values at the beginning of the code even if the paths have embedded spaces. They will be inserted at the proper time.
For the record, the first script I posted was VBScript which was installed on your system with Windows. All you need now is a dollar and a dream. ;D
There is a compiled help file for VBScript (script56.chm) which you can search for on your machine or you can download it from here (http://www.microsoft.com/downloads/details.aspx?familyid=01592c48-207d-4be1-8a76-1c4099d7bbb9&displaylang=en)
Except for REXX, IMO VBScript is one of the easiest script languages to learn and has much more functionality than batch code could ever hope to have.
Good luck. 8)
-
It works ...thanks very much !! :D
-
Hello,
As I looked for the same (i.e. a small script or tool to change the Windows wallpaper in a random way every day - and without downloading an .exe file...), I tried the VB script available at the URL: http://sites.google.com/site/sharerandomwallpapers/
It works fine and handles a variable number of files (the VB script listed above only handles 3 files or a constant number of files...).
I hope it will bring some help! :)
John