Hi all,
it's been a wile since my last post but was wondering is someoone see what i am missing... i have a simple printer script that run throught with no issue the on issue is the printer never gets added even though it say it does,, (Windoes 7)


 Code:
; * * *   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\,,xxxxxxxxxxxx,"
	$i1 = 0
	$sPrinterExist = ""
	$sRegKey4 = "HKEY_CURRENT_USER\Printers\Connections"
	$sSearchFor2 = "xxxxxxxxxxxx"
	$sSearchFor3 = "LPT"
	$SOffset = ""
	$sOffset2 = ""
	$sDefaultPrinter = ""
	$sDefaultALocalPrinter = ""
	$sNumberOfPrinters = 0
  	$sPrinterPrefix = ""
	$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 Tempe floor printers
		$sNumberOfPrinters = 1
		DIM  $aPrinters[1]
		$aPrinters[0] = "HP-LaserJet 4 Plus)"
		? "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

;********************************************************************************
;* Enterprise Standard Process - Except edit 	IF NOT INGROUP("xx xxxx-xxxxx")
;********************************************************************************


: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 Other Sites For Travelers		*
;********************************************************************************

	IF NOT INGROUP("xxx xxxx-xxxxx")
		GOTO CheckDefaultPrinter
	ELSE
	        $LoopCount = $LoopCount + 1
	        IF $LoopCount > 50
	                   MESSAGEBOX("There is an issue with one or more of the installed Printer Queues. Please submit a Work Request with Desktop Services to have this condition corrected","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 2


Edited by Allen (2012-01-15 05:04 PM)
Edit Reason: added code tags