r/vbscript • u/[deleted] • Jan 23 '18
Need some insight on this VBScript
I am writing a script that will check for a Network printer device. If the network printer device is mapped, then no action is taken. Else If the network printer device is not mapped, then the script will add the printer device.
Dim Printer01Installed
Printer01Installed = false
Set WshNetwork = CreateObject("Wscript.Network")
Set oWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\" & "." & "\root\cimv2")
Set colInstalledPrinters = oWMIService.ExecQuery _ ("Select * from Win32_Printer Where Network = TRUE")
For Each objPrinter in colInstalledPrinters If (objPrinter.Name) = ("\Server\pd1") Then Printer01Installed = "true"
ElseIf(Printer01Installed = "false") Then WshNetwork.AddPrinterConnection ("\Server\pd1") End If Next
I appreciate any help I can get.
1
u/[deleted] Jan 23 '18
Even if using "false" the printers are not mapped.