; *******************************************************************************************************
; * Printer Mapping Module of Site Logon Script - Printers.kix *
; * *
; * History: *
; * who when what *
; * Shawn Tipton 10.10.2011 Created *
; *******************************************************************************************************
; * * * O F F I C E P R I N T E R S C R I P T * * *
; Establish script global variables
$i1 = 0
$i2 = 0
$sRegValEnum = ""
$sRegKeyEnum = ""
$sRunThis = ""
$sRegkey3 = "HKEY_CURRENT_USER\Printers\Connections\,,xxx,"
$i1 = 0
$sPrinterExist = ""
$sRegKey4 = "HKEY_CURRENT_USER\Printers\Connections"
$sSearchFor2 = "xxxx"
$sSearchFor3 = "LPT"
$SOffset = ""
$sOffset2 = ""
$sDefaultPrinter = ""
$sDefaultALocalPrinter = ""
$sNumberOfPrinters = 1
$sPrinterPrefix = "HP"
$ipbyte3 = Val(LTrim(SubStr(@IPADDRESS0, 9, 3)))
$LoopCount = 0
;********************************************************************************
;* Build the array $aPrinters based on the value in string $ipbyte3
;* Set the number of printers in $sNumberOfPrinters and
;* set the value for $sPrinterPrefix used later in the script.
;* Jump to the subAddPrinters subroutine
;********************************************************************************
Select
Case $IPBYTE3 = xxx ; Values for Office
$sNumberOfPrinters = 4
Dim $aPrinters[1]
$aPrinters[0] = "HP-LaserJet (West)"
$aPrinters[1] = "HP-LaserJet (East)"
$aPrinters[2] = "HP-LaserJet (South)"
$aPrinters[3] = "HP-LaserJet (North)"
? "Printer array created."
Gosub SubAddPrinters
Goto PrinterCheckLoop
Case 1 ;If CASE is not meet execute the following commands
? "unknown case type (subnet)"
Goto End_Printers
EndSelect
;********************************************************************************
;* Standard Process - Except edit IF NOT INGROUP("xxxx-Users")
;********************************************************************************
:SubAddPrinters
;********************************************************************************
;* Check the registry location ($sRegKey3[$i4] +
;* $aPrinters) to determine if printer $aPrinters[$i4]
;* is currently installed. Otherwise use ADDPRINTERCONNECTION
;* to add this printer to the local system.
;********************************************************************************
? " Number of network printers on this floor = " + $sNumberOfPrinters
Do
;? "Index is " + $i1
? " Check for printer " + $aPrinters[$i1]
$sPrinterExists = ExistKey($sRegKey3 + $aPrinters[$i1])
If @ERROR = 0
? "Printer " + $aPrinters[$i1] + " already exists"
Else
$temp = AddPrinterConnection("\\" + $sSearchFor2 + "\" + $aPrinters[$i1])
? " " + $aPrinters[$i1] " created."
EndIf
$i1 = $i1 + 1
Until $i1 = $sNumberOfPrinters
? ""
$sPrinterExist = ""
$i1 = 0
Return
CLS
:PrinterCheckLoop
;********************************************************************************
;* Module To Remove Printer Mappings To Old Printers *
;********************************************************************************
If Not InGroup("Home-Users")
Goto CheckDPTefaultPrinter
Else
$LoopCount = $LoopCount + 1
If $LoopCount > 50
MessageBox("There is an issue with one or more of the installed Printer Queues." +
" Please Contact your DOMAIN MASTER", "Issue Removing Print Queue", 16, 30)
$sRegKeyEnum = ""
$i1 = 0 ;// Environment cleanup
$sOffset = ""
$LoopCount = 0
Goto CheckDefaultPrinter
EndIf
EndIf
? " Checking for Print Queues created by other sites"
$sRegKeyEnum = EnumKey($sRegKey4, $i1)
If @ERROR = 0
Do
$sOffset = InStr($sRegKeyEnum, $sSearchFor2)
If $sOffset = 0
? "Remove printer " + $sRegKeyEnum
$PrinterString = SubStr($sRegKeyEnum, 3, Len($sRegKeyEnum))
$TheComma = InStr($PrinterString, ",")
$ServerName = SubStr($PrinterString, 1, ( $TheComma - 1 ))
$PrinterName = SubStr($PrinterString, ( $TheComma + 1 ), Len($PrinterString))
DelPrinterConnection("\\" + $ServerName + "\" + $PrinterName)
Goto PrinterCheckLoop
Else
? "Printer " + $sRegKeyEnum + " is valid for this location"
EndIf
$i1 = $i1 + 1
$sRegKeyEnum = EnumKey($sRegKey4, $i1)
If $i1 = 50
$sRegKeyEnum = ""
MessageBox("There is an issue with one or more of the installed Printer Queues." +
" Please contact Desktop Services via a standard Work Request to have someone correct this condition.", 16, 30)
EndIf
Until @ERROR <> 0 Or $sRegKeyEnum = ""
EndIf
? ""
$i1 = 0 ;// Environment cleanup
$sOffset = ""
:CheckDefaultPrinter
;********************************************************************************
;* Check the value $sDefaultPrinter for $sServer and $sPrinterPrefix.
;* Warn user if this value is not valid and open Printers folder
;********************************************************************************
$sDefaultPrinter = ReadValue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device")
If @ERROR <> 0
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
$sOffset = InStr($sDefaultPrinter, $sSearchFor2)
$sOffset2 = InStr($sDefaultPrinter, $sPrinterPrefix)
If $sOffset = 0 Or $sOffset2 = 0
$sSubString1 = SubStr($sDefaultPrinter, 1, 2)
If $sSubString1 = "\\"
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 '"%systemroot%\system32\CONTROL.EXE" PRINTERS'
Else
? "Local Printer " + $sDefaultPrinter + " is the current default printer"
EndIf
Else
? "Network Printer " + $sDefaultPrinter + " is the current default printer"
EndIf
EndIf
$sOffset = "" ; Environment cleanup
$sOffset2 = ""
$sDefaultALocalPrinter = ""
:End_Printers
? "* * * P R I N T E R S C R I P T C O M P L E T E D * * *"
Sleep 5