childebrandt42

Worthless info……………Oh blinky lights!

Horizon View Printer Assignment Issues

Posted by

·

As most of you know there are some issues with printer management with Horizon View. There are many different ways to solve this problem, you can go out and get third party software, use some GPO scripting, or even just manually add the printers from there IP address and bypass the print server. I have had many issues deploying printers with GPO, like the GPO deployment not finishing in time and stopping, or just not running because of the huge amount of printers everyone wants, or default printers not changing. Why any one person needs 15 printers is beyond me but we have some users that want them.

I took the approach of cutting GPO out as much as possible. I decided to go with a LogOn and a Logoff Script.

The logoff script was designed to save your default printer to a txt file in the user’s Documents folder. As you see below.

'Save Default Printer to text file
'Chris Hildebrandt @childebrandt42
'Version 1.1 Oct 20th 2015 
'--------------------------------------------------------------------'

On Error Resume Next

Const ForWriting = 2
 
Set objNetwork = CreateObject("Wscript.Network")
 
strName = objNetwork.UserName
strDomain = objNetwork.UserDomain
strUser = strDomain & "\" & strName
 
'strText = strUser & vbCrLf
 
strComputer = "."
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

'Save Default Printer to text file

Set colPrinters = objWMIService.ExecQuery _
 ("Select * From Win32_Printer Where Default = TRUE")
 
For Each objPrinter in colPrinters
 strText = objPrinter.Name
Next
 
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Save Locatin for text file
'Edit this for the location you would like to save the file to. 
Set objFile = objFSO.CreateTextFile _
 ("C:\Users\" & strName & "\Documents\default.txt", ForWriting, False)
 
objFile.Write strText
 
objFile.Close

LogOn script was to add the printers to the user’s View Desktop and read the txt file created from the logoff script to assign the default printer.

'Assign Printers and set default printer
'Chris Hildebrandt @childebrandt42
'Version 1.1 Oct 20th 2015
'--------------------------------------------------------------------'

On Error Resume Next

Dim net
Set net = CreateObject("WScript.Network")

'Printers to be assigned
net.AddWindowsPrinterConnection "\\printserver\Printer UNC1"
net.AddWindowsPrinterConnection "\\printserver\Printer UNC2"
net.AddWindowsPrinterConnection "\\printserver\Printer UNC3"
net.AddWindowsPrinterConnection "\\printserver\Printer UNC4"

'Wait timer to set default printer
WScript.Sleep 120000

 
Dim objNetwork, strComputer, objFSO, strTextFile, strData, strLine, arrLines, strRunCmd, wshShell
CONST ForReading = 1
 
'Create a Network Object
Set objNetwork = CreateObject("Wscript.Network") 
 
'Get the local machine name from the Network Object
strComputer = objNetwork.ComputerName 
strName = objNetwork.UserName
 
'Pull in the info from text file for default printer
'Please change to the location of the text 
strTextFile = "C:\Users\" & strName & "\Documents\default.txt"
 
'Create a File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
'Open the text file - strData now contains the whole file
strData = objFSO.OpenTextFile(strTextFile,ForReading).ReadAll
 
'Split the text file into lines
arrLines = Split(strData,vbCrLf)
 
'Initialize the wshShell
Set wshShell = WScript.CreateObject ("WSCript.shell")
 
'Step through the lines
For Each strLine in arrLines
 
 If Len(strLine) > 0 Then
 'Only run the process on lines that aren't blank
 
' strRunCmd = "rundll32 printui.dll,PrintUIEntry /y /c\\" & strComputer & " /n" & strLine & ""
 strRunCmd = """printui.exe"" /y /c \" & strComputer & " /n """ & strLine & """"
' wscript.echo strRunCmd
 wshShell.Run strRunCmd
 
' wscript.echo "Processed printer: " & strLine
 End If
 
Next
 
'Cleanup
Set objFSO = Nothing

The LogOff script I created a GPO for the script to run on LogOff. And the LogOn script I added to the user’s LogOn script in AD. This way I can cut down on the GPO time to load and speed up the desktop load time.

I also modified my LogOn script to skip the printer assignment and just assign the user’s default printer from the txt file.

'Set default printer from text file
'Chris Hildebrandt @childebrandt42
'Version 1.1 Oct 20th 2015
'--------------------------------------------------------------------'

On Error Resume Next

Dim net
Set net = CreateObject("WScript.Network")

Dim objNetwork, strComputer, objFSO, strTextFile, strData, strLine, arrLines, strRunCmd, wshShell
CONST ForReading = 1
 
'Create a Network Object
Set objNetwork = CreateObject("Wscript.Network") 
 
'Get the local machine name from the Network Object
strComputer = objNetwork.ComputerName 
strName = objNetwork.UserName
 
'Pull in the info from text file for default printer
'Please change to the location of the text 
strTextFile = "C:\Users\" & strName & "\Documents\default.txt"
 
'Create a File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
'Open the text file - strData now contains the whole file
strData = objFSO.OpenTextFile(strTextFile,ForReading).ReadAll
 
'Split the text file into lines
arrLines = Split(strData,vbCrLf)
 
'Initialize the wshShell
Set wshShell = WScript.CreateObject ("WSCript.shell")
 
'Step through the lines
For Each strLine in arrLines
 
 If Len(strLine) > 0 Then
 'Only run the process on lines that aren't blank
 
' strRunCmd = "rundll32 printui.dll,PrintUIEntry /y /c\\" & strComputer & " /n" & strLine & ""
 strRunCmd = """printui.exe"" /y /c \" & strComputer & " /n """ & strLine & """"
' wscript.echo strRunCmd
 wshShell.Run strRunCmd
 
' wscript.echo "Processed printer: " & strLine
 End If
 
Next
 
'Cleanup
Set objFSO = Nothing
childebrandt42 Avatar

About the author

Hi, I’m Chris Hildebrandt, a Technology Generalist and passionate EUC Solutions Architect at Choice Solutions.

With hands-on experience from enterprise deployments to consulting, I specialize in virtualization, Omnissa Horizon, App Volumes, Azure Virtual Desktop, Nerdio, LoginVSI, Cisco UCS, Pure Storage and streamlining workflows through automation (PowerShell, APIs, and more).

Proud multi-year vExpert, Omnissa Tech Insider, Cisco Champion, former VMUG leader, and co-Leader of World of EUC in KC!

Active in the #vCommunity—let’s connect on EUC challenges, automation ideas, or modern workspaces! 🚀