#203320 - 2011-10-22 05:56 PM
Printer mapping ?????
|
Chan
Fresh Scripter
Registered: 2011-10-14
Posts: 15
Loc: Arizona
|
and yet another day ......
May be some one can tell me why the printer is not mapping .. the script run like it is designed to but the printers never get mapped, ran with debug and can not see where it goes arey. maybe a fresh pair of eyes can see what i am missing
; *******************************************************************************************************
; * 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
Edited by Mart (2011-10-23 10:48 PM) Edit Reason: Please use code tags when posting code. I have put a break in the long lines.
|
|
Top
|
|
|
|
#203321 - 2011-10-22 06:29 PM
Re: Printer mapping ?????
[Re: Chan]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
Try adding...
? "Error: "+@Error+@CRLF+"Error Desc: "+@SError After some of the statements you expect the script to run, to see whats happening. Also it's helpful to add a line with "get $" at the end so that the script will not close until you hit a key.
|
|
Top
|
|
|
|
#203323 - 2011-10-22 09:09 PM
Re: Printer mapping ?????
[Re: ShaneEP]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
It appears (to me at least) that you are over-complicating a lot of this. Here is an example of accomplishing the same results (if I made sense of your goto's and gosub logic correctly) using about half the code. You can take it or leave it. I think you're just shooting yourself in the foot by using the goto/gosub style of coding. It becomes so convoluted and difficult to troubleshoot, as you can probably already see.
; 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
Edited by ShaneEP (2011-10-23 11:35 PM)
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 235 anonymous users online.
|
|
|