#40625 - 2003-05-23 03:53 PM
Adding a printer UDF
|
Shaggydog
Fresh Scripter
Registered: 2003-05-20
Posts: 31
Loc: Mississauga, ON
|
Hey, I was originally posting this question in the "scripts" board, but I began to feel guilty asking those guys after reading the stuff they actually deal with.
Here's the issue I'm dealing with.
Windows NT network. Windows NT server.
I want to create a script that checks to see if the printer already exists on a machine, and if it doesn't exist, to add it.
What I've got so far is the Primapstate() udf, but I'm getting errors as I try to call it.
I have this.
if not primapstate("\\mother\WinLexT612) addprinterconnection("\\mother\WinLexT612") end if
I've looked in the help files but I think the problem here is that I'm TOO new. is this a function I need to call, and if so, How do I do it? Some sample script would be greatly appreciated. Thanks guys.
|
Top
|
|
|
|
#40626 - 2003-05-23 03:58 PM
Re: Adding a printer UDF
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
endif is one 'word'
is the UDF actually in your script, how are you calling it?
what is the error you are getting?
what version of kix are you using?
what client OS is it running on?
|
Top
|
|
|
|
#40629 - 2003-05-23 04:14 PM
Re: Adding a printer UDF
|
Chris S.
MM club member
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
quote: I've looked in the help files but I think the problem here is that I'm TOO new. is this a function I need to call, and if so, How do I do it?
The function needs to be included in your script (or called from another script). Here's your example with the UDF included...
if not primapstate("\\mother\WinLexT612") $Returncode=addprinterconnection("\\mother\WinLexT612") endif
function PriMapState($_Pri) if @inwin=1 if len(readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices",$_Pri)) if instr(readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),$_Pri) $PriMapState=2 else $PriMapState=1 endif endif else dim $_Root,$_C,$_C2 $_Root="HKLM\System\CurrentControlSet\control\Print\Printers" for $_C=0 to 259 $_C2=enumkey($_Root,$_C) If instr(READVALUE($_Root+"\"+$_C2,"Port"),$_Pri) If instr(READPROFILESTRING("%windir%\win.ini","windows","device"),$_Pri) $PriMapState = 2 Else $PriMapState = 1 Endif Endif if $_C2=259 $_C=$_C2 endif next endif endfunction
[ 23. May 2003, 16:16: Message edited by: Chris S. ]
|
Top
|
|
|
|
#40631 - 2003-05-30 02:39 PM
Re: Adding a printer UDF
|
Shaggydog
Fresh Scripter
Registered: 2003-05-20
Posts: 31
Loc: Mississauga, ON
|
Alright, the only problem with primapstate is that it doesn't see if the specific user in question has the printer installed, so much as if that printer is listed in the registry.
It took me a while to notice that as the problem here, but I really feel that's what it's come down to. On the machines at my work anywhere from 1 user to 10 users could be active on any given computer.
Your thoughts?
|
Top
|
|
|
|
#40633 - 2003-05-30 03:52 PM
Re: Adding a printer UDF
|
Shaggydog
Fresh Scripter
Registered: 2003-05-20
Posts: 31
Loc: Mississauga, ON
|
My apologies, your absolutely right.
I discovered that Addprinterconnection will add printers both by using the Share name of the printer, or the Actual name of the printer as seen in the "printers" folder.
If you use the share name, it will continue adding it because all it sees is the actual name of the printer on your computer, not the server share name.
Thanks for all your help guys, I really appreciate it.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 382 anonymous users online.
|
|
|