Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

How can i add a desktop wallpaper (background) to each machine that i install through WDS Windows deployment services.

Hi,

How can i add a desktop wallpaper (background) to each machine that i install through WDS Windows deployment services.
I use Microsoft deployment toolkit is there any option inbuilt or any script that i can push the background.

Regards
Sharath
Avatar of danengle
danengle

i'm not familiar with WDS, but this script can do the trick.  If a method exists(I'm sure there is) to run a script post-install, then this should do it.  Note, a reboot/relogin may be required to activate the change.
Const HKEY_CURRENT_USER = &H80000001
 
strComputer = "."
 
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
 
        strValue = "C:\WINDOWS\System32\Wallpaper1.bmp"
 
strKeyPath = "Control Panel\Desktop"
ValueName = "Wallpaper"
 
objReg.SetStringValue HKEY_USERS, strKeyPath, ValueName, strValue

Open in new window

Avatar of bsharath

ASKER

Thanks...
Can we mention a UNC path...
As the wallpaper has to be placed from a remote machine...

And will the settings on the machine be changed that when ever the wallpaper is removed by the user it inserts it back?
You can try changing the path to UNC, but I believe the file needs to be local.  You could set it to copy the wallpaper from a UNC path to the local machine.  If you need that code, let me know.

If you need to keep resetting the wallpaper back, you can set the script to run in the all users profile.  it will then execute on any user's login.

Just in case you need it, you can add the following.  Place this at line 4:
dim filesys, objOldFile, strComputer
Const HKEY_CURRENT_USER = &H80000001
strComputer = "." 
' strValue is the full location of the wallpaper
strValue = "C:\WINDOWS\System32\Wallpaper1.bmp"
' registry location 
strKeyPath = "Control Panel\Desktop"
' registry value to update
ValueName = "Wallpaper"
 
set filesys=CreateObject("Scripting.FileSystemObject")
' delete old file first in case a user overwrote it.
if filesys.fileexists("c:\destfolder\wallpaper.bmp") then 
    set objOldfile = filesys.GetFile("c:\destfolder\wallpaper.bmp")
    objOldFile.Delete
    set objOldFile = Nothing
end if
 
' now copy the new file.
If filesys.FileExists("\\UNC\Path\to\bmp\wallpaper.bmp") Then
   filesys.CopyFile "\\UNC\Path\to\bmp\wallpaper.bmp", "c:\destfolder\"
End If
' update registry to reference your bitmap
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
objReg.SetStringValue HKEY_USERS, strKeyPath, ValueName, strValue

Open in new window

the above is actually the fully modified script, no need to copy/past/insert into the first script tidbit.
Should the code be as below?
Const HKEY_CURRENT_USER = &H80000001
 
strComputer = "."
 dim filesys, objOldFile, strComputer
Const HKEY_CURRENT_USER = &H80000001
strComputer = "." 
' strValue is the full location of the wallpaper
strValue = "C:\WINDOWS\System32\Wallpaper1.bmp"
' registry location 
strKeyPath = "Control Panel\Desktop"
' registry value to update
ValueName = "Wallpaper"
 
set filesys=CreateObject("Scripting.FileSystemObject")
' delete old file first in case a user overwrote it.
if filesys.fileexists("c:\destfolder\wallpaper.bmp") then 
    set objOldfile = filesys.GetFile("c:\destfolder\wallpaper.bmp")
    objOldFile.Delete
    set objOldFile = Nothing
end if
 
' now copy the new file.
If filesys.FileExists("\\UNC\Path\to\bmp\wallpaper.bmp") Then
   filesys.CopyFile "\\UNC\Path\to\bmp\wallpaper.bmp", "c:\destfolder\"
End If
' update registry to reference your bitmap
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
objReg.SetStringValue HKEY_USERS, strKeyPath, ValueName, strValue
 
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
 
        strValue = "C:\WINDOWS\System32\Wallpaper1.bmp"
 
strKeyPath = "Control Panel\Desktop"
ValueName = "Wallpaper"
 
objReg.SetStringValue HKEY_USERS, strKeyPath, ValueName, strValue 

Open in new window

Should this line be an UNC path?

filesys.CopyFile "\\UNC\Path\to\bmp\wallpaper.bmp", "c:\destfolder\"

thought i pasted that in.  you got it.  the first paramater of .copyfile is the source, second is the destination.  
What are all the lines i need to change
All these 3 lines to?
strValue = "C:\WINDOWS\System32\Wallpaper1.bmp"
If filesys.FileExists("\\UNC\Path\to\bmp\wallpaper.bmp") Then
   filesys.CopyFile "\\UNC\Path\to\bmp\wallpaper.bmp", "c:\destfolder\"
What are all the lines i need to change
All these 3 lines to?
strValue = "C:\WINDOWS\System32\Wallpaper1.bmp"
If filesys.FileExists("\\UNC\Path\to\bmp\wallpaper.bmp") Then
   filesys.CopyFile "\\UNC\Path\to\bmp\wallpaper.bmp", "c:\destfolder\"
I tweaked it for easier modification.  Just change the values between "Values to Change" comment lines.
Const HKEY_CURRENT_USER = &H80000001
 
dim filesys, objOldFile, strComputer, strSourceFolder, strDestFolder, strFileName
strComputer = "."
'============== Begin Values to Change ================
' Source Directory
strSourceFolder = "\\UNC\Path\to\bmp\"
' Destination directory
strDestFolder = "c:\destfolder\"
 
' The filename that is stored in the source folder and 
' to be copied/refreshed in the Destination Folder
strFileName = "wallpaper.bmp"
 
'============== End Values to Change ================
' registry  and key location to update.  shouldn't need to update these unless changing it for other purposes
strKeyPath = "Control Panel\Desktop"
ValueName = "Wallpaper"
' strValue is the full location of the wallpaper
strValue = strDestFolder & strFileName
 
set filesys=CreateObject("Scripting.FileSystemObject")
' delete old file first in case a user overwrote it.
if filesys.fileexists(strDestFolder & strFileName) then 
    set objOldfile = filesys.GetFile(strDestFolder & strFileName)
    objOldFile.Delete
    set objOldFile = Nothing
end If
 
' now copy the new file.
If filesys.FileExists(strSourceFolder & strFileName) Then
   filesys.CopyFile strSourceFolder & strFileName, strDestFolder
End If
' update registry to reference your bitmap
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
objReg.SetStringValue HKEY_USERS, strKeyPath, ValueName, strValue
 
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
 
strValue = strDestFolder & strFileName
objReg.SetStringValue HKEY_USERS, strKeyPath, ValueName, strValue  

Open in new window

I tried the script.It copies the file to the location but does not add it as background...
Restarted the machine.When manually done it works...
I tried the script.It copies the file to the location but does not add it as background...
Restarted the machine.When manually done it works...
Had a little more time.  Realized I had some issues.  Word of advise when working with vbscript... Make sure you use "Option Explicit".  It forces variable declaration so if you mistype one somewhere in the script, you'll know it!  I thought I had that in there, but obviously not ;)

I also added a bunch of logic to check that the source file exists, destination dir exists (creates it if not) reports to the screen any errors.  If you want to add additional steps in the event of a failure, just look for the IF statements that check err.number and you can add whatever additional steps as you deem necessary (write to the event log, quit with a specific errorlevel etc).
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 2007
'
' NAME: 
'
' AUTHOR:  , 
' DATE  : 6/24/2008
'
' COMMENT: 
'
'==========================================================================
Option Explicit
Const HKEY_CURRENT_USER = &H80000001
 
dim filesys, objOldFile, strComputer, strSourceFolder, strDestFolder, strFileName, strKeyPath, ValueName, strValue, objReg
 
strComputer = "."
'============== Begin Values to Change ================
' Source Directory
strSourceFolder = "\\UNC\Path\to\bmp\"
' Destination directory
strDestFolder = "c:\destfolder\"
 
' The filename that is stored in the source folder and 
' to be copied/refreshed in the Destination Folder
strFileName = "wallpaper.bmp"
 
'============== End Values to Change ================
' registry  and key location to update.  shouldn't need to update these unless changing it for other purposes
strKeyPath = "Control Panel\Desktop"
ValueName = "Wallpaper"
' strValue is the full location of the wallpaper
strValue = strDestFolder & strFileName
 
set filesys=CreateObject("Scripting.FileSystemObject")
' delete old file first in case a user overwrote it.
 
' check if source file exists before doing anything
If filesys.FileExists(strSourceFolder & strFileName) Then
	' delete existing file
	if filesys.fileexists(strDestFolder & strFileName) Then 
	    set objOldfile = filesys.GetFile(strDestFolder & strFileName)
	    objOldFile.Delete
	    If Err.Number <> 0  then
			WScript.Echo "Error deleting old desktop image.  Errorlevel: " & Err.number
		End if
	    set objOldFile = Nothing
	end If
	' copy source file to destination
	' Create destination folder if it doesn't exist
	If not filesys.folderexists(strDestFolder) Then	
		filesys.CreateFolder(strDestFolder)
		If Err.Number <> 0  then
			WScript.Echo "Error creating Destination Dir.  Errorlevel: " & Err.number
		End If
	End If
	' copy file from source location
	filesys.CopyFile strSourceFolder & strFileName, strDestFolder
	If Err.Number <> 0 Then 
		WScript.Echo "Error copying bmp.  Errorlevel: " & Err.number
	End if
Else ' source file can't be reached(network issue?, access rights?) or mistyped path to file
	WScript.Echo "Source File cannot be found.  Doublecheck source location."
	
End If
 
' update registry to reference your bitmap
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strValue
If Err.Number <> 0 Then 
	WScript.Echo "Error updating registry value.  Errorlevel: " & Err.number
End if

Open in new window

Hi,

I get this

---------------------------
Windows Script Host
---------------------------
Source File cannot be found.  Doublecheck source location.
---------------------------
OK  
---------------------------


I have the wallpaper.bmp in the same folder where i run the script and the file's path is changed to the UNC path...

When opened manually it opens the wallpaper file

this worked for me.  ensure strSourceFolder has a trailing \.  For example:
strSourceFolder = "\\Server\bmpshare\"

If that appears correct, if you post your edited version of the script(feel free to change the server name if you think that is too personal), I'll see if I can find the issue.
Here is the code with my changes
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 2007
'
' NAME: 
'
' AUTHOR:  , 
' DATE  : 6/24/2008
'
' COMMENT: 
'
'==========================================================================
Option Explicit
Const HKEY_CURRENT_USER = &H80000001
 
dim filesys, objOldFile, strComputer, strSourceFolder, strDestFolder, strFileName, strKeyPath, ValueName, strValue, objReg
 
strComputer = "."
'============== Begin Values to Change ================
' Source Directory
strSourceFolder = "\\dev-mrd01\New Folder\Wallpaper.bmp"
' Destination directory
strDestFolder = "D:\New folder\"
 
' The filename that is stored in the source folder and 
' to be copied/refreshed in the Destination Folder
strFileName = "wallpaper.bmp"
 
'============== End Values to Change ================
' registry  and key location to update.  shouldn't need to update these unless changing it for other purposes
strKeyPath = "Control Panel\Desktop"
ValueName = "Wallpaper"
' strValue is the full location of the wallpaper
strValue = strDestFolder & strFileName
 
set filesys=CreateObject("Scripting.FileSystemObject")
' delete old file first in case a user overwrote it.
 
' check if source file exists before doing anything
If filesys.FileExists(strSourceFolder & strFileName) Then
	' delete existing file
	if filesys.fileexists(strDestFolder & strFileName) Then 
	    set objOldfile = filesys.GetFile(strDestFolder & strFileName)
	    objOldFile.Delete
	    If Err.Number <> 0  then
			WScript.Echo "Error deleting old desktop image.  Errorlevel: " & Err.number
		End if
	    set objOldFile = Nothing
	end If
	' copy source file to destination
	' Create destination folder if it doesn't exist
	If not filesys.folderexists(strDestFolder) Then	
		filesys.CreateFolder(strDestFolder)
		If Err.Number <> 0  then
			WScript.Echo "Error creating Destination Dir.  Errorlevel: " & Err.number
		End If
	End If
	' copy file from source location
	filesys.CopyFile strSourceFolder & strFileName, strDestFolder
	If Err.Number <> 0 Then 
		WScript.Echo "Error copying bmp.  Errorlevel: " & Err.number
	End if
Else ' source file can't be reached(network issue?, access rights?) or mistyped path to file
	WScript.Echo "Source File cannot be found.  Doublecheck source location."
	
End If
 
' update registry to reference your bitmap
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strValue
If Err.Number <> 0 Then 
	WScript.Echo "Error updating registry value.  Errorlevel: " & Err.number
End if

Open in new window

Here is the code with my changes
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 2007
'
' NAME: 
'
' AUTHOR:  , 
' DATE  : 6/24/2008
'
' COMMENT: 
'
'==========================================================================
Option Explicit
Const HKEY_CURRENT_USER = &H80000001
 
dim filesys, objOldFile, strComputer, strSourceFolder, strDestFolder, strFileName, strKeyPath, ValueName, strValue, objReg
 
strComputer = "."
'============== Begin Values to Change ================
' Source Directory
strSourceFolder = "\\dev-mrd01\New Folder\Wallpaper.bmp"
' Destination directory
strDestFolder = "D:\New folder\"
 
' The filename that is stored in the source folder and 
' to be copied/refreshed in the Destination Folder
strFileName = "wallpaper.bmp"
 
'============== End Values to Change ================
' registry  and key location to update.  shouldn't need to update these unless changing it for other purposes
strKeyPath = "Control Panel\Desktop"
ValueName = "Wallpaper"
' strValue is the full location of the wallpaper
strValue = strDestFolder & strFileName
 
set filesys=CreateObject("Scripting.FileSystemObject")
' delete old file first in case a user overwrote it.
 
' check if source file exists before doing anything
If filesys.FileExists(strSourceFolder & strFileName) Then
	' delete existing file
	if filesys.fileexists(strDestFolder & strFileName) Then 
	    set objOldfile = filesys.GetFile(strDestFolder & strFileName)
	    objOldFile.Delete
	    If Err.Number <> 0  then
			WScript.Echo "Error deleting old desktop image.  Errorlevel: " & Err.number
		End if
	    set objOldFile = Nothing
	end If
	' copy source file to destination
	' Create destination folder if it doesn't exist
	If not filesys.folderexists(strDestFolder) Then	
		filesys.CreateFolder(strDestFolder)
		If Err.Number <> 0  then
			WScript.Echo "Error creating Destination Dir.  Errorlevel: " & Err.number
		End If
	End If
	' copy file from source location
	filesys.CopyFile strSourceFolder & strFileName, strDestFolder
	If Err.Number <> 0 Then 
		WScript.Echo "Error copying bmp.  Errorlevel: " & Err.number
	End if
Else ' source file can't be reached(network issue?, access rights?) or mistyped path to file
	WScript.Echo "Source File cannot be found.  Doublecheck source location."
	
End If
 
' update registry to reference your bitmap
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strValue
If Err.Number <> 0 Then 
	WScript.Echo "Error updating registry value.  Errorlevel: " & Err.number
End if

Open in new window

line 21 needs to be just:
strSourceFolder = "\\dev-mrd01\New Folder\"


To see what happened, add this line after line 64:
wscript.echo "Source location as entered is: " & strSourceFolder & strFilename



After this...

WScript.Echo "Source File cannot be found.  Doublecheck source location."
correct.
Hi,

I get this

---------------------------
Windows Script Host
---------------------------
Script:      \\Sop\Ps\Wallpaperscript.vbs
Line:      59
Char:      2
Error:      File not found
Code:      800A0035
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------

I tried in some machine with different OS but there the Wallpaper.bmp just gets deleted after i run the script....
Hi,

I get this

---------------------------
Windows Script Host
---------------------------
Script:      \\Sop\Ps\Wallpaperscript.vbs
Line:      59
Char:      2
Error:      File not found
Code:      800A0035
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------

I tried in some machine with different OS but there the Wallpaper.bmp just gets deleted after i run the script....
ASKER CERTIFIED SOLUTION
Avatar of danengle
danengle

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks this worked....
Can you please remove all the user interfaces that popup...
Thanks this worked....
Can you please remove all the user interfaces that popup...
In a windows 2003 machine i get this box

---------------------------
Windows Script Host
---------------------------
Error copying bmp.  Errorlevel: 53
---------------------------
OK  
---------------------------
In a windows 2003 machine i get this box

---------------------------
Windows Script Host
---------------------------
Error copying bmp.  Errorlevel: 53
---------------------------
OK  
---------------------------
use cscript.exe to run the script instead of doubleclicking.  that will just echo the results to the screen instead of generating pop-ups.  

you can also do a search and replace for:
wscript.echo
 and replace it with:
'wscript.echo

the ' is recognized as a comment.
There must be some permission issue on that windows 2003 box.  the script is sound.
if doubleclicking on the script runs it, I strongly recommend changing the default behavior corp-wide to be EDIT instead of open.  it will prevent people from doubleclicking on scripts that could be malicious.