Page 1 of 1 1
Topic Options
#71502 - 2002-11-09 06:02 AM RFC - Clean-up of FAQ Post for Printer Setup/Capture
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Ref. FAQ - Default Printer

I am interested in cleaning up the following script..

It seems to work great..
  • What this does is to read in the default printer from the registry.
  • Checks to see if it is not Adobe Writer, Winfax, etc. exists. If so, it leaves.
  • If no printer is found, there is a check made for the INI file.
  • If the INI file is found, ADDPRINTERCONNECTION and SETDEFAULTPRINTER are initiated.
  • If the printer already exists, it skips the ADDPRINTERCONNECTION and SETDEFAULTPRINTER.
  • Once this done, it captures the printer to the INI file.
  • Lastly, a USE to LPT1 is done as we are doing more with Citrix.
code:
 ; -- Printer Configuration
; -- Kent Dyer
; -- Updated 8 August 2002
; -- Originally coded 15 August 2001
; -- 8 August 2002 - Fixed USE Commmand - Doh!
; -- 13 March 2002 - Added in debug flag. Thanks MCA!
; -- Updated on 25 February 2002 for the OS check
; -- This sets up for printers
; -- Captures the local Printer and writes to an INI file
; -- The reason for the INI is that the computer system may change location
; -- Also, if a new person logs in under a new profile, they will get the same printer
; -- This was written in frustration with Q252388
; -- http://support.microsoft.com/default.aspx?scid=kb;EN-US;q252388
; -- Comments and feedback are welcome to - dyerkb@myrealbox.com
; -- Code was inspired from - http://members.ams.chello.nl/a.westra2/800/prtshr8i.htm (no, I don't know Dutch :))

BREAK ON
CLS
:setprinter
IF "%OS%" <> "Windows_NT" ; -- is it winnt or 2K?
RETURN ; Not Windows NT/2K/XP (ADDRPRINTERCONNECTION AND SETDEFAULTPRINTER are not supported), so return
ELSE
$debug = "No" ; -- Set this to Yes for displaying the results
$ps = "%windir%\Printsetup.ini" ; -- Print Configuration File
; -- Read default printer string from registry
$subkey = "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows"
$value = ReadValue( $subkey, "Device" )
;?$value
; -- 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, "\\")
RETURN ; -- If they are using a local printer driver, return
; -- Otherwise, go on to delete the networked printer and re-add it
ENDIF

; -- If $VALUE = "", does a printer exist in the Registry?
IF $value = ""
; -- 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")
AddPrinterConnection ($def) ; -- Add the printer (only available on NT/2K)
SetDefaultPrinter ($ptr) ; -- Set the Printer to Default
;ELSE
; RETURN ; -- Printer does not exist in the Registry nor in the INI File, maybe a message here?
ENDIF
ENDIF

$offset = InStr( $value, "," ) ; Parse UNC only from string
IF $debug = "Yes"
?$offset + " Offset"
ENDIF
$len = $offset - 1
IF $debug = "Yes"
?$len + " Length"
ENDIF
$lpt1 = SUBSTR( $value, 1, $len )

IF $debug = "Yes"
; Display UNC value found
? "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
$RC=WRITEPROFILESTRING($ps,"Printers","Default",$lpt1) ; -- Get the whole UNC Path and Printer

$nlen = $offset - 3
IF $debug = "Yes"
?$nlen + " New Length"
ENDIF

; OK, So now let's remove the \\
$prtn = SUBSTR( $value, 3, $nlen )
IF $debug = "Yes"
?$prtn + " Removed \\"
ENDIF

; Now, Let's grab the printer name
$offset1 = INSTR( $prtn, "\" )
$offset1 = $offset1 + 1
IF $debug = "Yes"
?$offset1 + " Offset1"
ENDIF
$len1 = $offset1
IF $debug = "Yes"
?$len1 + " Second New Length"
ENDIF

$lptn = SUBSTR( $prtn, $offset1, $len1 )
IF $debug = "Yes"
?$lptn + " Printer Name"
ENDIF
$RC=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
RETURN
ENDIF

I look at this code and it seems pretty intensive for a relatively simple task.

Questions:
  • Am I doing too much?
  • Should the approach be done on an array?
  • Could this be done in a different way?
Thank you.
Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#71503 - 2002-11-10 03:36 AM Re: RFC - Clean-up of FAQ Post for Printer Setup/Capture
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Instead of
code:
IF "%OS%" <> "Windows_NT"

you should use
code:
IF @INWIN=2

By not using ADDPRINTERCONNECTION if a printer already exists, this printer will not receive updated printer drivers in case the drivers on the print server are upgraded.
_________________________
There are two types of vessels, submarines and targets.

Top
#71504 - 2002-11-10 07:39 AM Re: RFC - Clean-up of FAQ Post for Printer Setup/Capture
Kdyer Offline
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 ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#71505 - 2002-11-11 08:31 PM Re: RFC - Clean-up of FAQ Post for Printer Setup/Capture
Anonymous
Unregistered


Kdyer-
I am having a few problems with this script.
1) ; -- DO NOT DO ANYTHING
IF $debug_mode = "Yes"
? "FAX or Acrobat"
ENDIF
RETURN

I have set the default to the local printer.
When it reaches Return, here, the script quits.
So I went ahead and ";" it out

Later on, when the script gets to the
Use LPT1: $lpt1 /persistent
The scipt gives me a use error and spits out return.

I guess my problem is that when the default is a local printer, it does not capture the printer.
Any help?

Top
#71506 - 2002-11-11 08:53 PM Re: RFC - Clean-up of FAQ Post for Printer Setup/Capture
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
Have you tried commenting out all the returns and/or trapping for the value of @error @serror to see why USE was unsuccessful?
code:
Use LPT1: $lpt1 /persistent
if @error <> 0
"USE failed with error code "+@error+" "+@serror
endif



[ 11. November 2002, 22:25: Message edited by: Waltz ]
_________________________
We all live in a Yellow Subroutine...

Top
#71507 - 2002-11-11 11:03 PM Re: RFC - Clean-up of FAQ Post for Printer Setup/Capture
Anonymous
Unregistered


Ok-
One problem with the script that may or may not be a problem
When using the following:
Use LPT1: $lpt1 /persistent
It does not work.
I had to make it work by sharing the local printer.
Then the following line works:
USE LPT1: "\\@wksta\$lpt1" /persistent

Can you map a local printer to the lpt1 port without sharing the local printer?
If so, what would need to be done?

Top
#71508 - 2002-11-12 12:50 AM Re: RFC - Clean-up of FAQ Post for Printer Setup/Capture
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Normally, you do not MAP a local printer to an LPT port but CONNECT to it using the print manager. There's no need to map a local printer to an additional LPT port and the printer, by default, is always permanently available since the printer is connected on the computer-level and not the per-user level.
_________________________
There are two types of vessels, submarines and targets.

Top
#71509 - 2002-11-12 05:31 AM Re: RFC - Clean-up of FAQ Post for Printer Setup/Capture
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Jens raises a good point. If you had a printer on the USB port, for example you would do "printer pooling" use it on LPT1 too.

However... if you want.. This maybe it..

OK.. Let's whittle this down a bit.

code:
$subkey = "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows"
$value = ReadValue( $subkey, "Device" )
IF 0 = InStr($value, "") ; -- IT IS NULL
RETURN ; -- NO PRINTER NOR INI FILE FOUND
ENDIF

; -- Let's manipulate some strings

$offset = InStr( $value, "," ) ; Parse name from string
$len = $offset - 1
$lpt1 = SUBSTR( $value, 1, $len )

IF (ExistKey("HKEY_CURRENT_USER\Network\LPT1") = 0)
; -- 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

HTH,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#71510 - 2002-11-12 05:47 PM Re: RFC - Clean-up of FAQ Post for Printer Setup/Capture
Anonymous
Unregistered


Mapping is a poor choice of words.
What I want to do is capture the local printer to the ini file, then make that printer the default printer....each time they logon.
Is the best way to do this through the registry?
Do I use the setdefaultprinter command on a local printer?

Top
#71511 - 2002-11-12 05:57 PM Re: RFC - Clean-up of FAQ Post for Printer Setup/Capture
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
This should do it..

code:
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" )
IF 0 = InStr($value, "") ; -- IT IS NULL
RETURN ; -- NO PRINTER NOR INI FILE FOUND
ENDIF

; -- Let's manipulate some strings

$offset = InStr( $value, "," ) ; Parse name from string
$len = $offset - 1
$lpt1 = SUBSTR( $value, 1, $len )

$RC = WRITEPROFILESTRING($ps,"Printers","Default",$lpt1)

HTH,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#71512 - 2002-11-12 09:31 PM Re: RFC - Clean-up of FAQ Post for Printer Setup/Capture
Anonymous
Unregistered


Thanks for everyone's help. I got it to work.
Conclusion:
The script captures to an .ini file and then reads the file the next time to reset as default.
Thanks for the help

Top
#71513 - 2002-11-12 10:02 PM Re: RFC - Clean-up of FAQ Post for Printer Setup/Capture
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Can you post/share your final code?

This I am sure will come up again and we can post this as an addendum to the FAQ too.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#71514 - 2002-11-13 12:41 AM Re: RFC - Clean-up of FAQ Post for Printer Setup/Capture
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
#71515 - 2002-11-13 03:50 PM Re: RFC - Clean-up of FAQ Post for Printer Setup/Capture
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Please indent your code to make it more readable.
_________________________
There are two types of vessels, submarines and targets.

Top
#71516 - 2002-11-13 04:07 PM Re: RFC - Clean-up of FAQ Post for Printer Setup/Capture
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
jojo...
Check this out -->How do we check and format code for scripts?
_________________________
We all live in a Yellow Subroutine...

Top
#71517 - 2002-11-13 04:31 PM Re: RFC - Clean-up of FAQ Post for Printer Setup/Capture
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
jojo,
Please see the following FAQ on the use of CODE tags.

ABC's of KiXtart board etiquette and message to new forum users
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#71518 - 2002-11-13 06:26 PM Re: RFC - Clean-up of FAQ Post for Printer Setup/Capture
Anonymous
Unregistered


Sorry everyone. I went ahead and reedited my above post with the correct code and /code
Please let me know if there any more problems.

Top
#71519 - 2002-11-21 11:02 PM Re: RFC - Clean-up of FAQ Post for Printer Setup/Capture
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Hi everybody,

I have cleaned up Default Printer Setup Script and have added in jojopuppyfish's code as well. This is also cleaned up. [Smile]

This is reflected in the FAQ.

Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#71520 - 2002-11-23 07:45 AM Re: RFC - Clean-up of FAQ Post for Printer Setup/Capture
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
I believe that I have addressed Jens point about re-adding the printer on each login.

This has been updated in the FAQ section too..
Default Printer Configuration

Here is what the cleaned up code distills down to.
code:
BREAK ON
CLS
$subkey = "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows"
$windir = READVALUE("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion","SystemRoot")
$systemdrive = SUBSTR($windir,1,2)
IF EXIST($windir+"\Printsetup.ini")
DEL $windir+"\Printsetup.ini"
ENDIF
IF (GETFILEATTR("H:") & 16)
$ps = "H:\Scripts_DO_NOT_DELETE\Printsetup.ini"
IF ((GETFILEATTR("H:\Scripts_DO_NOT_DELETE") & 16) = 0)
MD "H:\Scripts_DO_NOT_DELETE"
ENDIF
ELSE
$ps = $systemdrive+"\Scripts\Printsetup.ini"
IF ((GETFILEATTR($systemdrive+"\Scripts") & 16) = 0)
MD $systemdrive+"\Scripts"
ENDIF
ENDIF
$value = ReadValue($subkey,"Device")
IF Exist($ps)
$lpt1 = READPROFILESTRING($ps,"Printers","Default")
$rc = AddPrinterConnection($lpt1)
$rc = SetDefaultPrinter($lpt1)
ELSE
$lpt1 = SUBSTR($value,1,InStr($value,",")-1)
$rc = AddPrinterConnection($lpt1)
$rc = SetDefaultPrinter($lpt1)
ENDIF
SLEEP 1
IF INSTR($value,"\\")
$rc = WRITEPROFILESTRING($ps,"Printers","Default",$lpt1)
USE LPT1: $lpt1 /del /persistent
USE LPT1: $lpt1 /persistent
ENDIF
RETURN

Comments and suggestions are welcome.

Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1046 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.129 seconds in which 0.079 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org