#71514 - 2002-11-13 12:41 AM
Re: RFC - Clean-up of FAQ Post for Printer Setup/Capture
|
Anonymous
Anonymous
Unregistered
|
I'd be honored. I changed a few things, and the intent of the script. The intent is to take a snapshot of the default printer. From them on, each time the user logs on, the user reads the ini file and sets that as the default printer. Now the only thing I need to do is to make it only for people with local printers. If its a usb printer port, it would be hklm\system\controlser001\services\usbprint Obviously, if LPT1 is hkeyCU\network\lpt1 I'll keep on looking. Here is the meat and the potatoes of it:
code:
;---Declares Values $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 $subkey = "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows" $value = ReadValue( $subkey, "Device" ) ; -- Read default printer string from registry
;Determines where windows is installed and creates .ini file IF exist("c:\nul") $ps = "c:\Scripts_DO_NOT_DELETE\Printsetup.ini" ; -- Print Configuration File IF GETFILEATTR("c:\Scripts_DO_NOT_DELETE") & 16 ELSE SHELL "%comspec% /c md C:\Scripts_DO_NOT_DELETE" ENDIF ;IF EXIST($windir+"\Printsetup.ini") ; DEL $windir+"\Printsetup.ini" ;ENDIF ELSE ; If there is no c drive, put it on the systemdrive 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
IF $debug_mode = "Yes" ?$value ENDIF
;Reads string from .ini IF EXIST("$ps") IF $debug_mode = "Yes" ? "NO PRINTER FOUND" ENDIF ; -- We should check for the INI File $def=READPROFILESTRING($ps,"Printers","Default") $ptr=READPROFILESTRING($ps,"Printers","PtrName") SetDefaultPrinter ($def) ; -- Set the Printer to Default Goto End ENDIF
;Let's manipulate some strings For Default Printer $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!!-------- $ = 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 :End
[ 13. November 2002, 18:25: Message edited by: jojopuppyfish ]
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 525 anonymous users online.
|
|
|