问题
Need help making this script true. i beleave the first part is done file, but registry needs to be reflected from information 4-8 thank you.
1 'this vbscript should be named DefualtWallpaper.vbs
2 'copy this file to a folder.
3 'cat.jpg image should be in same folder as vbscript.
dim filesys
set filesys=CreateObject("Scripting.FileSystemObject")
If filesys.FileExists("%cd%\cat.jpg%") Then
filesys.CopyFile "%cd%\cat.jpg%","%windir%\web\wallpaper\windows"
4.'change registry to new file
Set WShellObj=createobject("WScriptShell")
WShellObject.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\DesktopBackground","%WINDIR%\WINDOWS\Web\Wallpaper\Windows\cat.bmp","REG_EXPAND_SZ"
Set WShellObj=nothing
- i get a error at line 18 char 54 error expected 'end' code 800A03f6 from microsft VBScript combilation error. on a win 7 home 64bit,
- Key name:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes
- keytype:
REG_EXPAND_SZ
- key:
DesktopBackground
- Data:
%WINDIR%\WINDOWS\Web\Wallpaper\Windows\cat.bmp
回答1:
This VBScript for:
1-Run script as administrator
2-Copy my image to the directory where the background image saved
3-Change the current desk background image to my image From registry
4-Force Log off the current user to apply the change
'run the script as Administrator
If WScript.Arguments.Length=0 Then
CreateObject("Shell.Application").ShellExecute "wscript.exe",Chr(34)&WScript.ScriptFullName&Chr(34)&" Admin",Null,"runas",1
WScript.Quit
End If
'copy the image from to
Dim WShellObj : Set WShellObj=createobject("WScript.Shell")
Dim filesys : set filesys=CreateObject("Scripting.FileSystemObject")
If filesys.FileExists(WShellObj.ExpandEnvironmentStrings("%cd%")&"\cat.jpg") Then
WShellObj.Run "cmd.exe /c copy ""%cd%\cat.jpg"" %windir%\web\wallpaper\windows",0,False
End If
'change desktop wallpaper through registry
WShellObj.RegWrite "HKEY_CURRENT_USER\Control Panel\Desktop\Wallpaper","%WINDIR%\Web\Wallpaper\Windows\cat.jpg","REG_SZ"
'force log off to apply the change of wallpaper
Dim oSystem
For Each oSystem In GetObject ("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery("select * from Win32_OperatingSystem")
oSystem.Win32Shutdown 4
Next
回答2:
Try this one from spicework forum:
reg.exe load HKU\DefUser "C:\Documents and Settings\Default User\ntuser.dat"
reg.exe add "HKU\DefUser\Control Panel\Desktop" /v Wallpaper /d "c:\windows\wallpaper\desktop.bmp" /f
reg.exe unload HKU\DefUser
The link is here: http://community.spiceworks.com/scripts/show/327-batch-file-to-set-the-default-wallpaper
来源:https://stackoverflow.com/questions/21971471/creating-vbscript-to-change-defualt-wallpaper-on-win7home-machines