; Establish script global variables
$sSearchFor2 = "xxxx"
$sDefaultPrinter = ""
$sNumberOfPrinters = 1
$sPrinterPrefix = "HP"
$ipbyte3 = Trim(Split(@IPADDRESS0,".")[2])
;;;;;;;;; ADD PRINTERS BASED ON IP ADDRESS ;;;;;;;;;
SELECT
CASE $IPBYTE3 = xxx ; Values for Office
$sNumberOfPrinters = 4
$aPrinters = "HP-LaserJet (West)","HP-LaserJet (East)","HP-LaserJet (South)","HP-LaserJet (North)"
? "Printer array created."
For Each $p in $aPrinters
$nul = AddPrinterConnection("\\"+$sSearchFor2+"\" + $p)
Next
CASE 1 ;If CASE is not meet execute the following commands
? "unknown case type (subnet)"
? "* * * P R I N T E R S C R I P T C O M P L E T E D * * *"
sleep 5
Exit 0
ENDSELECT
;;;;;;;;; REMOVE PRINTERS THAT ARE NOT FROM sSearchFor2 ;;;;;;;;;
If INGROUP("Home-Users")
$printers = EnumPrinterConnections2()
For Each $p in $printers
If not InStr($p,$sSearchFor2)
$nul = DelPrinterConnection(Split($p,",")[0])
Endif
Next
Endif
;;;;;;;;; VERIFY THE DEFAULT PRINTER ;;;;;;;;;
$sDefaultPrinter = ReadValue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device")
IF @ERROR <> 0
$nul = MESSAGEBOX("Your default network printer is not set. Please choose a default network printer by right-clicking its icon from the printers"+
" folder and selecting 'Set As Default'" + CHR(13) + CHR(13) + "The Printers folder will now be opened","Default Network Printer Not Set",16,30)
RUN "CONTROL.EXE PRINTERS"
ELSE
IF NOT INSTR($sDefaultPrinter, $sSearchFor2) OR NOT INSTR($sDefaultPrinter, $sPrinterPrefix)
IF LEFT($sDefaultPrinter,2) = "\\"
$nul = MESSAGEBOX("Your default network printer is not set for this site. Please choose a default network printer by right-clicking its icon"+
" from the Printers folder and selecting 'Set As Default'" + CHR(13) + CHR(13) + "The Printers folder will now be opened","Default Network Printer Not Set",16,30)
RUN "CONTROL.EXE PRINTERS"
ELSE
? "Local Printer " + $sDefaultPrinter + " is the current default printer"
ENDIF
ELSE
? "Network Printer " + $sDefaultPrinter + " is the current default printer"
ENDIF
ENDIF
;;; PRE-MADE FUNCTIONS ;;;
Function EnumPrinterConnections2()
Dim $WshNetwork, $oPrinters, $i, $PrintArray[0]
$EnumPrinterConnections2=""
$WshNetwork = CreateObject("WScript.Network")
If Not @ERROR
$oPrinters = $WshNetwork.EnumPrinterConnections
For $i = 0 to $oPrinters.Count - 1 Step 2
$PrintArray[UBound($PrintArray)]=$oPrinters.Item($i+1)+','+$oPrinters.Item($i)
ReDim Preserve $PrintArray[UBound($PrintArray)+1]
Next
If UBound($PrintArray) > 0
ReDim Preserve $PrintArray[UBound($PrintArray)-1]
Else
$PrintArray = 0
EndIf
Else
$EnumPrinterConnections2=@ERROR
Exit $EnumPrinterConnections2
EndIf
$EnumPrinterConnections2=$PrintArray
EndFunction