Like most IT professionals, I’ve been using Bginfo to embed some useful information in the wallpaper of a users Desktop for some years now. So what you say! Well…not too long ago Warren Simondson of CTRL-ALT-DEL IT Consultancy created a couple of cool utilities called TSBackdrop and PCBackdrop. I was specifically interested in the TSBackdrop utility, as it automatically displays items such as the Client Computer Name, Client IP address, Username and the Server which the Client is logged on to, on the user’s desktop background. This is great for Terminal and Citrix servers, and something that Bginfo lacks.
However, I wanted the best of both words; the ability to display ordinary text, as well as displaying this useful client connection information on the user’s wallpaper. This is now easily achievable with thanks to the lastest release of Warren’s tools.
So my challenge was to first run Bginfo to create an updated bginfo.bmp, and then use TSbackdrop to reference the bginfo.bmp and create a TSBKDRP.BMP in the users “My Documents” folder. I basically wanted the desktop to look something like the following screenshot (without the red boxes of course).
So to achieve this I needed to copy the following 4 files to each Citrix server:
- Bginfo.exe
- Standard.bgi (the Bginfo template)
- TSBackdrop.exe
- ResetWallpaper.vbs (my script, which is what this article is all about)
You also need to place a Shortcut to the ResetWallpaper.vbs script in the “%ALLUSERSPROFILE%\Start Menu\Programs\Startup” folder, so that it runs every time a user logs in.
Be sure to set the Target of the shortcut to %SystemRoot%\system32\cscript.exe //nologo “%ProgramFiles%\BGInfo\ResetWallpaper.vbs”
…and the Start in to %ProgramFiles%\BGInfo
You can place these 4 files anywhere. I have always placed them in a “%ProgramFiles%\BGInfo” folder. Hence the references to it in these scripts.
This is all handled by the following InstallBGInfo.vbs script.
‘ BGInfo and TSBackdrop installation script.
‘
‘ For Terminal/Citrix Servers we are using a combination of SystemInternal’s BgInfo and
‘ CTRL-ALT-DEL’s TSbackdrop to create a nice informative wallpaper for all Terminal/Citrix
‘ server users. The BGInfo.bmp file is placed in their %TEMP% folder and the TSBKDRP.BMP
‘ is placed in their “My Documents” or “Personal” folder.
‘
‘ Before we proceed we first need to check that the “Terminal Services” (TermServ) service
‘ is running, otherwise using the WMI provider to query the Win32_TerminalServiceSetting
‘ properties will return a null value. Note that the WMI provider namespace is slighly
‘ different between Windows 2003 and Windows 2008.
‘
‘ The script has also been structured to deploy to ONLY BGInfo to non Terminal/Citrix
‘ servers. In this case, the BGInfo.bmp file is placed in the %SystemRoot% folder.
‘
‘ Version 1.3 released on 21st October 2009.
‘ Written by Jeremy@jhouseconsulting.com on 26th November 2008.
‘
Option Explicit
Dim objFSO, objFolder, wshShell, strOS, oShellLink, strRole, strBGI
Dim strSystemRoot, strProgramFiles, strAUStartup, strScriptPath
Dim strProgramFolder, strCommandLine, blnReturn
set WshShell = WScript.CreateObject(“WScript.Shell”)
set objFSO = CreateObject(“Scripting.FileSystemObject”)
strOS = GetOSFamily()
strRole = WshShell.ExpandEnvironmentStrings(“%Role%”)
Select Case ucase(strRole)
Case “XENAPP”
strBGI = “CitrixXenApp.bgi”
Case “RDS”
strBGI = “MicrosoftRDS.bgi”
Case Else
strBGI = “Standard.bgi”
End Select
strSystemRoot = WshShell.ExpandEnvironmentStrings(“%SystemRoot%”)
strProgramFiles = WshShell.ExpandEnvironmentStrings(“%ProgramFiles%”)
strAUStartup = WshShell.SpecialFolders(“AllUsersStartup”)
strScriptPath = Left(WScript.ScriptFullName, InstrRev(WScript.ScriptFullName, “\”))
‘Create the Program Files folder
strProgramFolder = strProgramFiles & “\BGinfo”
If objFSO.FolderExists(strProgramFolder) Then
Set objFolder = objFSO.GetFolder(strProgramFolder)
‘ WScript.Echo strProgramFolder & ” already exists.”
Else
Set objFolder = objFSO.CreateFolder(strProgramFolder)
‘ WScript.Echo “Created ” & strProgramFolder
End If
‘Copy the files and templates
objFSO.CopyFile strScriptPath & “Bginfo.exe”, strProgramFolder & “\”, True
If isTerminalServer(strOS) Then
objFSO.CopyFile strScriptPath & “ResetWallpaper.vbs”, strProgramFolder & “\”, True
objFSO.CopyFile strScriptPath & “TSBackdrop.exe”, strProgramFolder & “\”, True
Else
objFSO.CopyFile strScriptPath & “Bginfo.txt”, strProgramFolder & “\”, True
End If
objFSO.CopyFile strScriptPath & strBGI, strProgramFolder & “\Standard.bgi”, True
If NOT isTerminalServer(strOS) Then
‘ Run BGInfo, which will create the BGInfo.bmp file.
‘ This will then allow us to give users modify permissions on the file.
strCommandLine = chr(34) & strProgramFolder & “\Bginfo.exe” & chr(34) & ” ” & chr(34) & strProgramFolder & “\standard.bgi” & chr(34) & ” /timer:0 /NOLICPROMPT”
WshShell.Run strCommandLine,1,True
‘ Check for the existence of the BGInfo.bmp file. If it doesn’t exist, call the MonitorFileCreation
‘ subroutine and pass it the folder and file to monitor.
If NOT objFSO.FileExists(strSystemRoot & “\BGInfo.bmp”) Then
Call MonitorFileCreation(strSystemRoot,”BGInfo.bmp”)
End If
‘ Set permissions on the BGInfo.bmp file to allow users to modify it.
‘ Note that you can either use xcacls.vbs or xcacls.exe here. I chose to use xcacls.vbs, which
‘ is automatically copied to each server during the automated server build. Also note that you
‘ use M for modify rights with xcacls.vbs, whilst xcacls.exe uses C.
strCommandLine = “cscript.exe ” & strSystemRoot & “\XCACLS.vbs ” & strSystemRoot & “\BGInfo.bmp /E /G Users:M”
WshShell.Run strCommandLine,1,True
End If
‘Create the Start Menu Startup folder Shortcut
If isTerminalServer(strOS) Then
Set oShellLink = WshShell.CreateShortcut(strAUStartup & “\ResetWallpaper.lnk”)
oShellLink.TargetPath = chr(34) & strSystemRoot & “\system32\cscript.exe” & chr(34)
oShellLink.Arguments = “//nologo ” & chr(34) & strProgramFolder & “\ResetWallpaper.vbs” & chr(34)
If objFSO.FileExists(strProgramFolder & “\Bginfo.exe”) Then
oShellLink.IconLocation = strProgramFolder & “\Bginfo.exe” & “,0”
End If
Else
Set oShellLink = WshShell.CreateShortcut(strAUStartup & “\BGInfo.lnk”)
oShellLink.TargetPath = chr(34) & strProgramFolder & “\Bginfo.exe” & chr(34)
oShellLink.Arguments = chr(34) & strProgramFolder & “\” & strBGI & chr(34) & ” /timer:0 /NOLICPROMPT”
End If
oShellLink.WorkingDirectory = strProgramFolder
oShellLink.Save
Set WshShell = Nothing
Set objFSO = Nothing
Set objFolder = Nothing
Set oShellLink = Nothing
WScript.Quit(0)
Sub MonitorFileCreation(strDirectory, strFile)
Dim strFullPathandFile, strComputer, objWMIService, colMonitoredEvents
Dim objLatestEvent, strNewFile, arrNewFile, strFileName
strFullPathandFile = strDirectory & “\” & strFile
strDirectory = chr(34) & Replace(strDirectory,”\”,”\\\\”) & chr(34)
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\\” & _
strComputer & “\root\cimv2”)
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
(“SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE ” _
& “Targetinstance ISA ‘CIM_DirectoryContainsFile’ and ” _
& “TargetInstance.GroupComponent= ” _
& “‘Win32_Directory.Name=” & strDirectory & “‘”)
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
strNewFile = objLatestEvent.TargetInstance.PartComponent
arrNewFile = Split(strNewFile, “=”)
strFileName = arrNewFile(1)
strFileName = Replace(strFileName, “\\”, “\”)
strFileName = Replace(strFileName, Chr(34), “”)
If StrComp(strFileName,strFullPathandFile, 1) = 0 Then
Exit Do
End If
Loop
Set objWMIService = Nothing
Set colMonitoredEvents = Nothing
Set objLatestEvent = Nothing
End Sub
Function GetOSFamily()
Dim strComputer, oWMIService, colOSInfo, oOSProperty, strCaption, strOSFamily
strComputer = “.”
Set oWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)
Set colOSInfo = oWMIService.ExecQuery(“Select * from Win32_OperatingSystem”)
For Each oOSProperty in colOSInfo
strCaption = oOSProperty.Caption
Next
If InStr(1,strCaption, “2008”, vbTextCompare) Then strOSFamily = “W2K8”
If InStr(1,strCaption, “2003”, vbTextCompare) Then strOSFamily = “W2K3”
GetOSFamily = strOSFamily
Set oWMIService = Nothing
Set colOSInfo = Nothing
End Function
Function isTerminalServer(strOS)
Dim strComputer, strNameSpace, objWMIService, colItems, objItem
strComputer = “.”
If ucase(strOS) = “W2K3” Then
strNameSpace = “\root\cimv2”
Else
strNameSpace = “\root\cimv2\TerminalServices”
End If
Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\\” & strComputer & strNameSpace)
Set colItems = objWMIService.ExecQuery _
(“Select * from Win32_TerminalServiceSetting”)
For Each objItem in colItems
Select Case objItem.LicensingType
Case “2”
isTerminalServer = True
Case “4”
isTerminalServer = True
Case Else
isTerminalServer = False
End Select
Next
Set objWMIService = Nothing
Set colItems = Nothing
End Function
The ResetWallpaper.vbs script is as follows:
‘ We are using a combination of SystemInternal’s BgInfo and CTRL-ALT-DEL’s TSbackdrop to create a nice
‘ informative wallpaper for all Terminal/Citrix server users.
‘
‘ Thanks to Warren Simondson at CTRL-ALT-DEL for making the required modifications to TSbackdrop so
‘ that I could reference the BGinfo.bmp bitmap file.
‘
‘ Version 1.2 released on 21st October 2009.
‘ Written by Jeremy@jhouseconsulting.com on 27th October 2008.
‘
Option Explicit
Dim WshShell, fso, strProgramFiles, strSystemRoot, strUserTemp, strKey
Dim strBGInfoLocation, strTSBackdropLocation, strCommandLine
set WshShell = WScript.CreateObject(“WScript.Shell”)
set fso = CreateObject(“Scripting.FileSystemObject”)
strProgramFiles = WshShell.ExpandEnvironmentStrings(“%ProgramFiles%”)
strSystemRoot = WshShell.ExpandEnvironmentStrings(“%SystemRoot%”)
strUserTemp = WshShell.ExpandEnvironmentStrings(“%Temp%”)
strKey = “HKCU\Control Panel\Desktop\”
strBGInfoLocation = strProgramFiles & “\BGInfo\Bginfo.exe”
strTSBackdropLocation = strProgramFiles & “\BGInfo\TSBackdrop.exe”
If fso.FileExists(strBGInfoLocation) Then
If RegValueExists(strKey & “Wallpaper”) Then
WshShell.RegDelete strKey & “Wallpaper”
End If
strCommandLine = chr(34) & strBGInfoLocation & chr(34) & ” ” & chr(34) & strProgramFiles & “\BGInfo\standard.bgi” & chr(34) & ” ” & “/timer:0 /NOLICPROMPT”
WshShell.Run strCommandLine, 7, True
End If
If fso.FileExists(strTSBackdropLocation) Then
If fso.FileExists(strUserTemp & “\bginfo.bmp”) Then
strCommandLine = chr(34) & strTSBackdropLocation & chr(34) & ” ” & chr(34) & strUserTemp & “\bginfo.bmp” & chr(34)
ElseIf fso.FileExists(strUserTemp & “\bginfo.bmp”) Then
strCommandLine = chr(34) & strTSBackdropLocation & chr(34) & ” ” & chr(34) & strSystemRoot & “\bginfo.bmp” & chr(34)
Else
strCommandLine = chr(34) & strTSBackdropLocation & chr(34)
End If
WshShell.Run strCommandLine, 7, True
End If
Set WshShell=Nothing
set fso=Nothing
wscript.quit(0)
Function RegValueExists(sRegValue)
‘ Returns True or False based of the existence of a registry value.
Dim oShell, RegReadReturn
Set oShell = CreateObject(“WScript.Shell”)
RegValueExists = True ‘ init value
On Error Resume Next
RegReadReturn = oShell.RegRead(sRegValue)
If Err.Number <> 0 Then
RegValueExists = False
End if
On Error Goto 0
Set oShell = Nothing
End Function
So now we can display useful and informative information for users that will make it easier for them to differentiate between their “normal” desktop, and that of their Citrix/Terminal server session, or even a Virtual Desktop session, and also provide them with the relevant information needed when communicating with the IT Helpdesk Support Staff, such as their Client name, IP address, and server they are connected to.
How cool is that???
But wait…it gets even cooler!
I am also using Login Consultants ReconnAct! to run the ResetWallpaper.vbs script when a user reconnects to a disconnected session. This works well because if a user reconnects to a session from a different client, or they have obtained a new IP address, etc, this information will be “dynamically” updated on their wallpaper.
I have to end this article with some limitations:
- The TSbackdrop information would only display when positioned in the centre of the image. Warren has clearly documented this in the TSBackdrop.txt file.
- The TSBKDRP.BMP file can get to 2 or 3 MB in size, depending on the screen resolution of the session. This is also because I have BGInfo configured to create it’s bmp output file in True Colour (24 bit), and TSBKDRP.BMP bases itself on this. Since it’s placed in the user’s “My Documents” folder, this means that it’s typically located on a File server, and not local to the Citrix/Terminal server. Perhaps Warren can add an option so that it’s placed in the %TEMP% or “%USERPROFILE%\Local Settings\Application Data” folder. Then it remains local to the server, and does not get effected by roaming profiles and/or redirected folders. After all, it’s just made up of session information, relevant only to that server/session.
Some may think that I’ve gone to such enormous efforts for little gain. I strongly disagree. The use of these cool utilities, and implementing them correctly, adds to the useability and supportability of the overall solution.
Download the scripts in one convenient zip.
A couple of final comments.
- I have tested these scripts on Windows 2003 and Windows 2008 32-bit and 64-bit servers.
- Don’t use the wallpaper to display messages to the users. Too much background text is messy. You are better off using a Message Of The Day banner.
Enjoy!!!