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

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 ""

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

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




Date Votes

Please sign in to leave a comment.

Didn't find what you were looking for?

New post