Set default printer for View floating desktop and Persona Management
Sometime ago I asked a question over at the VMware forum about how to set default network printers on a VMware View 5.0 floating pool that used Persona Management as Persona Management wasn’t keeping this user setting on it’s own. The printers would be added to the VM just not remember the default printer setting. I’ll admit I forgot to update the thread, but a work around was devised which I’ll share below.
Set View Desktop default printer using vbs script
Using this .vbs script I was able to have network printers installed and set as default upon a user logging into their View floating pool desktop.
[sourcecode language=”vb”]’ Installs network printer and sets default
‘ Created: 03/03/2013, By: Michael Tabor
Option Explicit
On Error Resume Next
Dim objNetwork, objSysInfo, objUser, strGroup
‘ Initialize constants with Group names
‘ AD groups should follow this convention:
‘ "!Group###name" entered here in all CAPS
Const Kentucky = "cn=!KY_Insurance"
Const Ohio = "cn=!OH_Insurance"
‘ Create objects and extract strGroup values
Set objNetwork = CreateObject("WScript.Network")
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
‘ Groups are polled and listed in an array. If only 1
‘ non-builtin group exists, the 1st line errors and
‘ the 2nd line will hold the value
strGroup = UCase(Join(objUser.MemberOf))
strGroup = UCase(objUser.MemberOf))
‘ If logic testing strGroup for the values in Const groups
If InStr(strGroup, UCASE(Kentucky)) Then
objNetwork.AddWindowsPrinterConnection ‘ Adds printer
"\\kentucky-print-server\ky-ins-printer" ‘ Printer network location
objNetwork.SetDefaultPrinter ‘ Sets default printer
"\\kentucky-print-server\ky-ins-printer"
ElseIf InStr(strGroup, UCASE(Ohio)) Then
objNetwork.AddWindowsPrinterConnection
"\\ohio-print-server\oh-ins-printer"
objNetwork.AddWindowsPrinterConnection
"\\ohio-print-server\oh-office-printer"
objNetwork.SetDefaultPrinter
"\\ohio-print-server\oh-ins-printer"
End If
Set objNetwork = Nothing
Set objSysInfo = Nothing
Set objUser = Nothing
WScript.Quit[/sourcecode]
So a little more background that might be useful – the floating pool is a pool that was for our Insurance department that was used by agents in two different states (Kentucky and Ohio). Each of the users was in a different usergroup based on their office/location.
This script works by looking at the usergroups each user is a member of upon log-in and then installs the users required printer(s) and sets a default. The process is nearly instant or within just a few seconds.
How the vbs script works
The break down of the important parts of the script is this:
[sourcecode language=”vb”]Const Kentucky = "cn=!KY_Insurance"
Const Ohio = "cn=!OH_Insurance"
[/sourcecode]
Constants are assigned for each usergorup using Kentucky and Ohio and looking for usergroups !KY_Insurance and !OH_Insurance respectively.
Then based on their usergroup membership the printer(s) was added and default set. For example say the member was part of the !KY_Insurance usergroup the following code would be ran for them:
[sourcecode language=”vb”]If InStr(strGroup, UCASE(Kentucky)) Then
objNetwork.AddWindowsPrinterConnection ‘ Adds printer
"\\kentucky-print-server\ky-ins-printer" ‘ Printer network location
objNetwork.SetDefaultPrinter ‘ Sets default printer
"\\kentucky-print-server\ky-ins-printer"
[/sourcecode]
This code goes to the printer server (\\kentucky-print-server) and adds a printer (ky-ins-printer), the last line sets that printer as default. You can see above that for the Ohio users that office had two printers added and then one set as default. So this can be expanded upon for any additional printers needed.
The script can be added to GPO and ran upon user login or placed on the VM parent image in the start-up folder:
%appdata%\Microsoft\Windows\Start Menu\Programs\Startup
Using this same script as well as Persona Management, I’ve been able to convert many persistent view desktop pools into floating pools as well. Works great and nice to have fewer persistent desktop pools.
If you know of any way to improve the script please share!
Download script: view-default-printer.vbs
Why not use Group Policy Preferences, which can do this with zero lines of code? Just a thought. -Jeremy Moskowitz, Group Policy MVP
Group Policy Preferences could certainly be another way to achieve the same result.
Correct me if I’m wrong, but isn’t this a feature that is available in Server 2008 and newer? Our AD controller in this environment is Server 2003.
You are hereby corrected. GPPreferences only requires that the client have the GPPreferences moving parts (which Windows 7 and later has.) The DC type and domain mode.. do not matter.
Thanks for the info. There’s always more than one way to skin a cat!
If ThinPrint is enabled, the default printer configured in the Client will override these selections unless disabled in the View Client