Important Notice: On February 29th, this community was put into read-only mode. All existing posts will remain but customers are unable to add new posts or comment on existing. Please feel to join our Community Discord for any questions and discussions.

VBS Script inside Batch File

Help needed, i'm trying to deploy a batch file where it copes over a vbs script then runs it,

I've got it to create the folder on the target PC and to copy over the VBs script, but it doesn't run the script to install the printer

Don't have GPO so can't use that

Batch File

echo off
cls

rem echo %computername%

mkdir c:\hptemp

xcopy "\\DESKTOP-0814DA\PDQ_Files\HPColourLaserJet5550PCL6\add\AddPrinter.vbs" c:\hptemp

cscript "c:\hptemp\AddPrinter.vbs"

VBs Script

Set wshNetwork = WScript.CreateObject ("WScript.Network")
strComputer = wshNetwork.ComputerName
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True

Install "192.168.1.116"

sub Install(strIP)
InstallPrinterPort strIP
end Sub

strBasePrinter = "HP Printer Far Right Hand Side"
strPrinterName = "HP Universal Printing PCL 6"
strINFPath = "\\DESKTOP-0814DA\PDQ_Files\HPColourLaserJet5550PCL6\hpcu180u.inf"
strIPPort = "IP_192.168.1.116"
Set objShell = CreateObject("WScript.Shell")
strCommand = "cmd /c rundll32 printui.dll,PrintUIEntry /if /b """ & strBasePrinter & """ /f " & strINFPath & " /r """ & strIPPort & """ /m """ & strPrinterName & """ & /Z"
objShell.Run strCommand, 1, True

Sub InstallPrinterPort(strIP)
Set colInstalledPorts = objWMIService.ExecQuery _
("Select Name from Win32_TCPIPPrinterPort")
For each objPort in colInstalledPorts
If objPort.Name="IP_" & strIP then exit sub
Next

Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_
objNewPort.Name = "IP_" & strIP
objNewPort.Protocol = 1
objNewPort.HostAddress = strIP
objNewPort.PortNumber = "9100"
objNewPort.SNMPEnabled = False
objNewPort.Put_
end Sub

 

0

Comments

2 comments
Date Votes