Page 1 of 1 1
Topic Options
#40625 - 2003-05-23 03:53 PM Adding a printer UDF
Shaggydog Offline
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 Offline
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?
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#40627 - 2003-05-23 04:04 PM Re: Adding a printer UDF
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22332
Loc: OK
total re-write of those 3 lines brings us to:
code:
if not primapstate("\\mother\WinLexT612")
$Returncode=addprinterconnection("\\mother\WinLexT612")
endif

_________________________
!

download KiXnet

Top
#40628 - 2003-05-23 04:11 PM Re: Adding a printer UDF
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11162
Loc: Boston, MA, USA
I have to wonder about your naming scheme. If MOTHER is a print server, would MOTHERINLAW be a crash-prone backup print server, then? [Big Grin]

code improvement in preparation of KiXgolf:
code:
$printer='\\mother\WinLexT612'
if not primapstate($printer)
$rc=addprinterconnection($printer)
endif



[ 23. May 2003, 16:12: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#40629 - 2003-05-23 04:14 PM Re: Adding a printer UDF
Chris S. Offline
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
#40630 - 2003-05-23 04:17 PM Re: Adding a printer UDF
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11162
Loc: Boston, MA, USA
Please take a look at the FAQ Forum, e.g. How to use UDFs
_________________________
There are two types of vessels, submarines and targets.

Top
#40631 - 2003-05-30 02:39 PM Re: Adding a printer UDF
Shaggydog Offline
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
#40632 - 2003-05-30 02:53 PM Re: Adding a printer UDF
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11162
Loc: Boston, MA, USA
That is incorrect. The UDF checks whether the current user has the printer by checking the appropriate registry keys. If the printer is not installed for that user, then these registry keys do not exist. If does not matter whether other users have that printer installed on the particular computer.
_________________________
There are two types of vessels, submarines and targets.

Top
#40633 - 2003-05-30 03:52 PM Re: Adding a printer UDF
Shaggydog Offline
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
Page 1 of 1 1


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

Who's Online
0 registered and 166 anonymous users online.
Newest Members
amelindarķe, Nims123, davidscroegh, davidscroe, DFGHJGH
17625 Registered Users

Generated in 0.037 seconds in which 0.013 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