#71504 - 2002-11-10 07:39 AM
Re: RFC - Clean-up of FAQ Post for Printer Setup/Capture
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
I was thinking about the @INWIN when I posted it here.. I don't think I have the whole updated script from work here.
Let me try this again as we don't use W9x anymore.
code:
;BREAK ON ;CLS $debug_mode = "No" ; -- Set this to Yes to see what is going on $windir = READVALUE("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion","SystemRoot") $systemdrive = SUBSTR($windir,1,2) ; -- This will show C:\ or M:\ or what drive windows is installed on
IF exist("H:\nul") $ps = "H:\Scripts_DO_NOT_DELETE\Printsetup.ini" ; -- Print Configuration File IF GETFILEATTR("H:\Scripts_DO_NOT_DELETE") & 16 ELSE SHELL "%comspec% /c md H:\Scripts_DO_NOT_DELETE" ENDIF IF EXIST($windir+"\Printsetup.ini") DEL $windir+"\Printsetup.ini" ENDIF ELSE IF EXIST($windir+"\Printsetup.ini") DEL $windir+"\Printsetup.ini" ENDIF IF exist($systemdrive+"\Scripts\nul") $ps = $systemdrive+"\Scripts\Printsetup.ini" ; -- Print Configuration File ELSE SHELL "%comspec% /c md "+$systemdrive+"\Scripts" $ps = $systemdrive+"\Scripts\Printsetup.ini" ; -- Print Configuration File ENDIF ENDIF $subkey = "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows" $value = ReadValue( $subkey, "Device" ) ; -- Read default printer string from registry IF $debug_mode = "Yes" ?$value ENDIF ; -- We Need to test for the existence of a Network Share being used ; -- This is done in the event of someone using Acrobat Writer ; -- Or a FAX driver instead of a networked printer as default
IF 0 <> InStr($value, "") ; -- IT IS NOT NULL IF $debug_mode = "Yes" ? "Something found" ENDIF IF 0 <> InStr($value, "\\") ; -- IT HAS \\ - network Printer IF $debug_mode = "Yes" ? "Network Printer" ENDIF ELSE ; -- DO NOT DO ANYTHING IF $debug_mode = "Yes" ? "FAX or Acrobat" ENDIF RETURN ENDIF ENDIF
IF 0 = InStr($value, "") ; -- IT IS NULL IF $debug_mode = "Yes" ? "NO PRINTER FOUND" ENDIF ; -- We should check for the INI File IF 1 = Exist($ps) ; -- The INI File does exist, let's read it and use the info $def=READPROFILESTRING($ps,"Printers","Default") $ptr=READPROFILESTRING($ps,"Printers","PtrName") $rc = AddPrinterConnection ($def) ; -- Add the printer (only available on NT/2K) $rc = SetDefaultPrinter ($def) ; -- Set the Printer to Default $value = ReadValue( $subkey, "Device" ) ; -- Read default printer string from registry ENDIF ENDIF
IF 0 = InStr($value, "") ; -- IT IS NULL RETURN ; -- NO PRINTER NOR INI FILE FOUND ENDIF
; -- Let's manipulate some strings
$offset = InStr( $value, "," ) ; Parse UNC only from string IF $debug_mode = "Yes" ?"Offset "+$offset ENDIF $len = $offset - 1 IF $debug_mode = "Yes" ?"Length "+$len ENDIF
$lpt1 = SUBSTR( $value, 1, $len )
; Display UNC value found IF $debug_mode = "Yes" ? "LPT1 = " + $lpt1 + " (Default Printer)" ENDIF
; -- Now, we have the Default Printer, let's capture it!! ; -- While we have the chance, let's capture the printer for any new users that may use the machine ;IF 0 <> EXIST"%windir%\Printsetup.ini" ; -- Uncomment this line as well as the next endif to leave the INI file alone
$ = WRITEPROFILESTRING($ps,"Printers","Default",$lpt1) ; -- Get the whole UNC Path and Printer
$nlen = $offset - 3 IF $debug_mode = "Yes" ?"New Length "+$nlen ENDIF
; OK, So now let's remove the \\ $prtn = SUBSTR( $value, 3, $nlen ) IF $debug_mode = "Yes" ?$prtn + " Removed \\" ENDIF
; Now, Let's grab the printer name $offset1 = INSTR( $prtn, "\" ) $offset1 = $offset1 + 1 IF $debug_mode = "Yes" ?"Offset1 " + $offset1 ENDIF
$len1 = $offset1 IF $debug_mode = "Yes" ?"New Length1 " + $len1 ENDIF
$lptn = SUBSTR( $prtn, $offset1, $len1 )
IF $debug_mode = "Yes" ?$lptn + " Printer Name" ? ?"Script is complete, Press Any Key to continue" GET $k ENDIF
$ = WRITEPROFILESTRING($ps,"Printers","PtrName",$lptn) ; -- Capture the Name of the Printer
;EndIf ; -- Done writing to the INI file
; -- Actual mapping - Re-Map the printer for LPT1 ; -- CHECK TO SEE IF LPT1 WAS DONE WITH A NET USE IF 0 = ExistKey("HKEY_CURRENT_USER\Network\LPT1") ; -- If the printer has been mapped then delete it to refresh the connection ; -- Delete the printer USE LPT1: $lpt1 /del /persistent ; -- Refresh the connection to the printer as LPT1 with the string captured above USE LPT1: $lpt1 /persistent RETURN ELSE ; -- ASSUME THE PRINTER HAS NOT BEEN DONE WITH A NET USE COMMAND ; -- Add it in as LPT1 anyway USE LPT1: $lpt1 /persistent RETURN ENDIF
Kent [ 10. November 2002, 16:20: Message edited by: kdyer ]
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1336 anonymous users online.
|
|
|