none
Printer install script hangs when being ran as part of imaging with MDT RRS feed

  • Question

  • I have created the following script (and many others like it for different printers) that works perfectly when ran on it's own. However, when it is ran as part of the imaging process using MDT, the printer gets installed, but the command line never exits allowing the script to move on to set the printer as the default printer. The reason I am doing this is to make the printer a local printer so that no matter who logs into a particular computer, will get the printer. Group Policy really isn't an option for scripting printers because of the large number of students and our Active Directory is no long broken down by Room numbers in each school. All student computers are put in one OU and all staff computers are put into another OU under each school OU.

    There is probably a better way of doing this, but I know enough VBScript coding to get by and zero PowerShell coding. I've been meaning to learn, just haven't had the time.

    So, ultimately, my question is, does anyone know what might be the issue that when the script is ran by double-clicking on it, it works perfectly, no matter if logged in as a domain user of the local Administrator account, but when ran through MDT, it hangs up? The network share the scripts are running from have permissions set up correctly. The user account that is used when the script is launched through MDT is the local Administrator account. There are no error messages on the screen, but while the script is hung up and I try to run another script, I do get an "Operation could not be performed. error 0x000006be." That's the entire error message. Nothing in Event Viewer about this error. I've read this could be anywhere from a driver issue to a Print Spooler issue. I know it's neither of these, because when the port is created, I am stopping/restarting the Print Spooler service and the driver is the correct driver. I do know it is getting hung up on the rundll32 command, because if I put a wscript.echo after calling the command line, the echo never comes up.

    I've been up all night working on this issue and I'm probably not explaining it correctly and leaving some things out, so please ask questions and I'll try to answer. I'm using a similar script (similar in the way this script is written) to update the BIOS on HP computers and it works perfectly every time.

    Thanks for your help,

    Mike

    Option Explicit
    
    Dim objShell, strFolder, filesys, strCurrentPath, strParentPath, strGrandParentPath
    Dim strComputer, colServiceList, objService, strIP, strBasePrinter, strINFPath, strIPPort, objWMIService, WshNetwork
    Dim strPrinterName, colInstalledPorts, objPort, objNewPort, strCommand, strCommand2
    Dim strDrive, strNetLoc
    
    '/\/\/\/\/\/\/\/\/\/\/\/\/\
    'ONLY CHANGE THESE TWO THINGS ONLY
    '==========================
    strIP = \\tsc46\MM-Lab-Media Ctr P4015 'Redirecting Printer Port to Print Server
    strBasePrinter = "MM-MC-HPLJP4015"  'What you want the printer to be named
    '==========================
    '/\/\/\/\/\/\/\/\/\/\/\/\/\
    strPrinterName = "HP Universal Printing PCL 5" '//////MUST BE WHAT THE DRIVER NAME IS\\\\\\\
    
    '///////////////////////////////////////////////////////////////////////////
    'Determine path script is running from to use for location of printer driver
    '///////////////////////////////////////////////////////////////////////////
    Set objShell = WScript.CreateObject("WScript.Shell")
    strFolder =  objShell.CurrentDirectory
    'msgbox strFolder
    
    '///////////////////////////////////////////////
    'Get Parent Directory of where script is running
    '///////////////////////////////////////////////
    Set filesys = CreateObject("Scripting.FileSystemObject")
    strCurrentPath = filesys.GetParentFolderName(WScript.ScriptFullName)
    strParentPath = filesys.GetParentFolderName(strCurrentPath)
    strGrandParentPath = filesys.GetParentFolderName(strParentPath)
    'msgbox strCurrentPath & vbCrLf & strParentPath & vbCrLf & strGrandParentPath
    
    '//////////////////
    'Map Network Drive
    '//////////////////
    If (Left(strParentPath,2)) = "\\" Then
    Set WshNetwork = CreateObject("WScript.Network") 
    strDrive = "Q:" 
    strNetLoc = strParentPath
    WshNetwork.MapNetworkDrive strDrive, strNetLoc
    Else
    strDrive = strFolder
    End If
    'msgbox strDrive
    
    '//////////////////////////////////////////////////////////
    'Installing Printer
    '//////////////////////////////////////////////////////////
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True 
    
    strINFPath = strParentPath & "\~Drivers\pcl5-x64-5.9.0.18326\hpcu170t.inf"
    strIPPort = strIP
    
    ' Start the install of the printer 
    InstallPrinterPort strIP
    Wscript.Sleep 2000
    
    strCommand = ("cmd.exe /c rundll32 printui.dll,PrintUIEntry /if /b """ & strBasePrinter & """ /f """ & strINFPath & """ /r """ & strIPPort & """ /m """ & strPrinterName & """")
    'msgbox strCommand
    Wscript.Sleep 2000
    objShell.Run strCommand,0,True
    
    Wscript.Sleep 10000
    
    Set WshNetwork = CreateObject("WScript.Network")
    WshNetwork.SetDefaultPrinter strBasePrinter
    SetDefaultPrinter strBasePrinter, objShell
    
    '================== 
    Sub SetDefaultPrinter(strBasePrinter, objShell)
    	Dim sDevice
    	sDevice = objShell.RegRead("HKEY_USERS\S-1-5-19\Software\Microsoft\Windows NT\CurrentVersion\Devices\" & strBasePrinter)
    	If not sDevice = "" Then
    		objShell.Run "reg load HKEY_USERS\defaultuser ""C:\users\default\ntuser.dat"" ",, TRUE  
    		objShell.RegWrite "HKEY_USERS\defaultuser\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device", strBasePrinter & "," & sDevice
    		objShell.Run "reg unload HKEY_USERS\defaultuser",, TRUE
    	End If
    End Sub
    
    Sub InstallPrinterPort(strIP)
    	Const HKLM = &h80000002 
    	Dim wmiSvc, spooler, reg
    	Set wmiSvc = GetObject("winmgmts:\\.\root\cimv2") 
    	Set spooler = wmiSvc.Get("Win32_Service.Name='spooler'") 
    	Set reg = GetObject("winmgmts:root\default:StdRegProv") 
    '		First check whether the port exists already
    '		msgbox strIP
    		Set colInstalledPorts =  objWMIService.ExecQuery("Select * from Win32_Printer")
    		For each objPort in colInstalledPorts
    '			msgbox objPort.Name
    			If objPort.Name = strIP then exit sub ' We have a result, so no need to add port
    		Next
    
    		spooler.StopService 
    		reg.SetStringValue HKLM, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports", strIP, "" 
    		spooler.StartService
    End Sub
    
    If strDrive="Q:" Then
        objNetwork.RemoveNetworkDrive strDrive, True, True
    End If

    Saturday, June 20, 2015 10:04 AM

Answers

  • I think I found the issue, which isn't with the script or MDT. THe issue is because the computer is not joined to the domain when the printer is getting installed. Because I'm using the HP Universal Print Driver and trying to connect to the Print Server share, there is no authentication to get to the Print Server Share in place. I tested this by removing a computer from the domain, mapping a drive to the location of the printer script and when ran, I get a popup from Windows stating a program running on this computer is trying to display a message. When I click on SHow Message, I get the following screen.

      

    So, now it looks like I need to move this to a different forum.

    • Marked as answer by mtarggart Saturday, June 20, 2015 11:14 AM
    Saturday, June 20, 2015 11:14 AM