Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How can I create a registry file for xp to change desktop backgrounds to a batch file or vbs script?

Posted on 2008-09-29
4
Medium Priority
?
627 Views
Last Modified: 2008-12-28
Recently I have been able to push a batch script to change the desktop background in GPO policies for each workstation through the server

This is the batch file:       copy \\server\sharename.jpg C:

Also, I put the same UNC above in the GPO: Administrative Template, Desktop, Active Desktop, Active Desktop Wallpaper and Enabled Active Desktop.

This works fine, all workstations/ users get whatever desktop I want them to get but, the desktop icons do not use drop shadow. Therefore the icons do not blend with the desktop. Locally on a workstation I could right click on My Computer , Advanced, if it were not if my restrictions on each workstation/user I would be able to Performance Settings, Visual Effects, Custom, Selec/Check use drop shadows for icon labels on the desktop. Usually that does the trick but when I modify GPOs I longer can choose this option or it does not work.
0
Comment
Question by:jeamrotae
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 71

Accepted Solution

by:
Chris Dent earned 2000 total points
ID: 22597123

Hey,

The attached VbScript will take the wallpaper defined at the top, copy it to the client (into C:\documents and settings\somebody) and set it with a few parameters described in the comments.

The file should be bmp, anything else will fail to set when the script runs UpdatePerUserSystemParameters. I believe because it performs an implicit conversion when you set a jpg through the GUI.

HTH

Chris
Option Explicit
 
' Network and local locations for the wallpaper file
Const WALLPAPER_SOURCE = "\\servers\share\wallpaper.bmp"
 
Sub SetWallpaper
	' Copies and sets the client wallpaper
 
	Const REG_HKCU = &H80000001
 
	Dim objShell, objFileSystem, objFile, objRegistry
	Dim strWallpaperDestination, strKeyPath, strCommand
 
	' Get the current user profile so we can copy the wallpaper there.
	Set objShell = CreateObject("WScript.Shell")
	strWallpaperDestination = objShell.ExpandEnvironmentStrings("%USERPROFILE%")
 
	' Get the wallpaper file from the source
	Set objFileSystem = CreateObject("Scripting.FileSystemObject")
	Set objFile = objFileSystem.GetFile(WALLPAPER_SOURCE)
 
	' Update the destination path to include the file name
	strWallpaperDestination = strWallpaperDestination & "\" & objFile.Name
	objFile.Copy strWallpaperDestination, True
	Set objFileSystem = Nothing
 
	' Connect to the Registry on the local machine
	Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
 
	' Set the values for the Wallpaper
	strKeyPath = "Control Panel\Desktop"
	objRegistry.SetStringValue REG_HKCU, strKeyPath, "Wallpaper", strWallpaperDestination
 
	' Set the Position to Stretch
	objRegistry.SetStringValue REG_HKCU, strKeyPath, "TileWallpaper", "0"
	objRegistry.SetStringValue REG_HKCU, strKeyPath, "WallpaperStyle", "2"
	Set objRegistry = Nothing
 
	' Update the system settings (refresh)
	strCommand = "RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters"
	objShell.Run strCommand, 1, True
	Set objShell = Nothing
End Sub
 
SetWallpaper

Open in new window

0
 

Author Comment

by:jeamrotae
ID: 22598061
Chris Dent: Thanks but, I wanted to ask
I  just added this to your script. I don't see anything else to modify.
' Network and local locations for the wallpaper file
Const WALLPAPER_SOURCE = "\\server1\pic\ NYC.bmp"

Chris Dent:
Do these lines apply to what I am doing
' Get the current user profile so we can copy the wallpaper there.
      Set objShell = CreateObject("WScript.Shell")
      strWallpaperDestination = objShell.ExpandEnvironmentStrings("%USERPROFILE%")

And

' Connect to the Registry on the local machine
      Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
 
What I want to do with this script is put it in my logon script in Group Policy (maybe change the picture file name and extension to bmp like you said), \\server\sharedfolder\pic.bmp for different groups and put the scripts in different OUs so whoever gets the script at the workstation the desktop background would change for different users. My problem is the background icon desktop shadow does not work when I use the batch file eventhough it works well otherwise.

I just trying if I apply to xp registry the background and icon would show correctly.
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 22598124

> maybe change the picture file name and extension to bmp like you said

Open with MSPaint and save as .bmp. Changing the name won't change the format and even though it stop picture viewers opening it normally.

> strWallpaperDestination = objShell.ExpandEnvironmentStrings("%USERPROFILE%")

Just expands the User Profile environmental variable as a safe place to copy the wallpaper to without requiring admin rights. You can see the contents by typing this into the command line:

echo %UserProfile%

>       Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")

Simply a connection to the registry on the local machine (dot is the local machine). It's how the script sets the wallpaper.

> My problem is the background icon desktop shadow does not work when I use the
> batch file eventhough it works well otherwise

I'll take another look at that setting at home.

Chris
0
 

Author Comment

by:jeamrotae
ID: 22598361
ok Chis Dent

please get back to me because the use shadow icon does not work
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
Wouldn't it be nice if objects in Active Directory automatically moved into the correct Organizational Units? This is what AutoAD aims to do and as a plus, it automatically creates Sites, Subnets, and Organizational Units.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question