Page 1 of 1 1
Topic Options
#126281 - 2004-09-08 02:56 PM local printer prob.
pong Offline
Fresh Scripter

Registered: 2004-08-27
Posts: 14
Loc: Zeist, The Netherlands
Sorry if im keep comming with newbie questions, or the most simple question, but i just need to know :-)
What is the deal with setting local printers default and differerent users and userrights?
My script sets up local printers as default, if there is none, it will connect to a network printer.
If i install a local printer on lpt1, and login AS A DIFFERENT USER (roaming profiles, w2k), the lpt1 printer will be in the Start --> Settings --> Printers list but the script will not see the lpt1 printer on lpt1.
If i login as the user who installed the lpt1 printer, the script picks it up, setting it default.
I think it has to do with userrights because i cant remove the lpt1 printer as a different user than the one who installed it.
But all users have enough rights to install printers and connect to network printers....

Hope y'all understand my problem....

If you need to see the code, just ask.

pong

Top
#126282 - 2004-09-08 03:13 PM Re: local printer prob.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, I must wonder how you script sees any printers.
thus I must also ask you to post it.
_________________________
!

download KiXnet

Top
#126283 - 2004-09-08 03:27 PM Re: local printer prob.
pong Offline
Fresh Scripter

Registered: 2004-08-27
Posts: 14
Loc: Zeist, The Netherlands
Here it is, i used an udf from http://www.gwspikval.com/jooel/UDF/ by Radimus and changed it.


    Lpt1Printer()
    Function Lpt1Printer()
    Dim $index,$inst_printers,$PrinterPorts,$port_type

    $index=0
    $PrinterPorts="HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts"

    :loopprinters
    $inst_printers=EnumValue($PrinterPorts,$index)

    If @error=0
    ? "$inst_printers"
    $port_type=ReadValue("$PrinterPorts","$inst_printers")
    ? "$port_type"
    If InStr("$port_type","LPT1")
    ? "lpt1 found"
    $=SetDefaultPrinter("$inst_printers")
    $FoundLpt1 = 1
    Return

    EndIf
    Else
    Return
    EndIf
    $index=$index+1


    GoTo loopprinters

    EndFunction

    If $FoundLpt1 = 1
    ? "Found Lpt1, dont install network printer"
    Else
    ? "No Lpt1, install network printer"
    EndIf


It will check the registry for the printers and their ports, then checks if any port matches "lpt1". If so, it will set the lpt1 printer default, else it does nothing.
Script works fine.

Top
#126284 - 2004-09-08 03:38 PM Re: local printer prob.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
just as I thought....

check this:
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=82672&page=29&view=collapsed&sb=3&o=all&fpart=1

what's the difference (yes, the udf is not for this purpose) is that it checks totally different location.
local printers are in there.
_________________________
!

download KiXnet

Top
#126285 - 2004-09-08 03:41 PM Re: local printer prob.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
oh, and if they aren't, you can kick me hard.
_________________________
!

download KiXnet

Top
#126286 - 2004-09-08 03:45 PM Re: local printer prob.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
and started wondering...
HKLM would be lot better place for these :P
_________________________
!

download KiXnet

Top
#126287 - 2004-09-08 03:52 PM Re: local printer prob.
pong Offline
Fresh Scripter

Registered: 2004-08-27
Posts: 14
Loc: Zeist, The Netherlands
Ok, things are starting to make (more) sense
So im checking the wrong registry key?
should i check HKLM\System\CurrentControlSet\control\Print\Printers if a local printer is installed?
Do you think that every user will then be able to set that printer to default using the script?

Top
#126288 - 2004-09-08 03:57 PM Re: local printer prob.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
users default printer is their own business, no?

did you check that devices location in HKCU?
_________________________
!

download KiXnet

Top
#126289 - 2004-09-08 04:02 PM Re: local printer prob.
pong Offline
Fresh Scripter

Registered: 2004-08-27
Posts: 14
Loc: Zeist, The Netherlands
Not sure if i understand...
A user installs a local printer on lpt1.
A different user logs on.
Now my script has to set THAT local printer standard.
So, is that HKCU or HKLM?

Top
#126290 - 2004-09-08 04:15 PM Re: local printer prob.
pong Offline
Fresh Scripter

Registered: 2004-08-27
Posts: 14
Loc: Zeist, The Netherlands
Wait, should it matter which reg key i check?
As long as i am able to retrieve "lpt1" and the printer name connected to it, i should be able to map that printer name right?

Top
#126291 - 2004-09-08 04:22 PM Re: local printer prob.
pong Offline
Fresh Scripter

Registered: 2004-08-27
Posts: 14
Loc: Zeist, The Netherlands
Or how can i map a local printer which was installed by a different user and set it default.......
Am i getting too complex..... just let me know...

Top
#126292 - 2004-09-08 05:30 PM Re: local printer prob.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Instead of asking the board so many questions, ask them of yourself and run a few tests to confirm.

Local printers are in HKLM while default printer is in HKCU.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#126293 - 2004-09-09 12:36 PM Re: local printer prob.
pong Offline
Fresh Scripter

Registered: 2004-08-27
Posts: 14
Loc: Zeist, The Netherlands
Sorry sorry
Ok, ive ran some tests.
Now my code looks like this:


    Lpt1Printer()
    Function Lpt1Printer()
    Dim $index2,$KeyName,$KeyValue

    $index2 = 0

    :loopprinters

    $KeyName = EnumKey("HKLM\System\CurrentControlSet\control\Print\Printers",$index2)
    $KeyValue = ReadValue("HKLM\System\CurrentControlSet\control\Print\Printers\$keyname","Port")

    If @error=0
    ? "$KeyName"
    @CRLF
    ? "$KeyValue"
    @CRLF
    If InStr("$KeyValue","LPT1")
    ? "lpt1 found, setting default..."
    $=SetDefaultPrinter("$KeyName")
    @CRLF
    @SERROR
    @CRLF
    ? "$KeyName"
    @CRLF
    $NietVerder = 1
    Return
    EndIf
    Else
    Return
    EndIf
    $index2=$index2+1
    GoTo loopprinters

    EndFunction

    If $NietVerder = 1
    ? "Lpt1 found, dont look for network printers."
    Else
    ? "install network printer"
    EndIf


But if i run the code for different users on the same pc, the script will see the reg key and say that it has found the lpt1 printer. But when you check the printer list, it will not be standaard... The script only sets the local printer default for the person who installed it...

Any ideas how to set the local printer default for every user who logs on the pc?

Top
#126294 - 2004-09-09 01:01 PM Re: local printer prob.
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Code could do with a bit of a tidy up, and contains a subtle bug which may or may not cause you problems.

Try this (untested - I don't have any entries in the reg key):
Code:
Break ON

$=SetOption("Explicit","ON")
$=SetOption("WrapAtEOL","ON")

Function Lpt1Printer()
Dim $iIndex,$sPrinter,$sPort
Dim $PRINTERKEY

$PRINTERKEY="HKLM\System\CurrentControlSet\control\Print\Printers"
$iIndex=0

$sPrinter = EnumKey($PRINTERKEY,$iIndex)
While Not @ERROR AND $sPrinter
"Printer: "+$sPrinter+@CRLF
$sPort = ReadValue($PRINTERKEY+$sPrinter,"Port")
If @ERROR=0 AND $sPort
" Port: "+$sPort+@CRLF
If InStr($sPort,"LPT1")
" LPT1 found, setting default"+@CRLF
If SetDefaultPrinter($sPrinter)
" Error setting default printer: "+@ERROR+", "+@SERROR+@CRLF
$Lpt1Printer=@ERROR
Exit $Lpt1Printer
Else
" Default printer set ok!"+@CRLF
$Lpt1Printer=0
Exit $Lpt1Printer
EndIf
EndIf
EndIf
$iIndex=$iIndex+1
$sPrinter = EnumKey($PRINTERKEY,$iIndex)
Loop
; Set exit and error values to "not found"
$Lpt1Printer=2
Exit $Lpt1Printer
EndFunction

If Lpt1Printer()=0
"LPT1: found, don't look for network printers."+@CRLF
Else
"LPT1: Not found, reason: "+@SERROR+@CRLF
"Set network printer here..."+@CRLF
EndIf


Top
Page 1 of 1 1


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

Who's Online
0 registered and 194 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.075 seconds in which 0.036 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