cwhitmore
(Starting to like KiXtart)
2004-01-20 11:20 PM
Adding Network Printer?

I started working on this a few months ago, but had to drop it. Now I'M BACK!!!
I want to setup a script that checks to see if a user is already setup on a printer, if not add that printer.
I tried using ADDPRINTERCONNECTION with the following command:
If ADDPRINTERCONNECTION ("\\server\HP4000N-IT") = 0
net use lpt1: \\oak2000\HP4000N-IT
EndIf
There is a Net2Fax that installs by default to LPT1, but that can be mapped over.
I did a search on other posts and someone suggested using the ADDPRINTER UDF. Can someone send me a link on how to use UDF's?
thanks,
Carlton.


Sealeopard
(KiX Master)
2004-01-20 11:34 PM
Re: Adding Network Printer?

Why don't you go to the FAQ Forum and read the post "How to use UDF's"? There are also other printer-related UDFs in the UDF forum.

LonkeroAdministrator
(KiX Master Guru)
2004-01-20 11:51 PM
Re: Adding Network Printer?

you don't need to have any udf as ADDPRINTERconnection() does ADD the PRINTER.
if you only want to check the map state of printer, look at www.kixhelp.com/udfs for primapstate()


ShaneEP
(MM club member)
2004-01-21 12:38 AM
Re: Adding Network Printer?

The first problem I see is that you are using 'net use' which is not a Kix command. You should use the 'use' command like so...

Code:
use lpt1: '\\oak2000\HP4000N-IT'



tjcarst
(Hey THIS is FUN)
2004-01-21 02:54 AM
Re: Adding Network Printer?

Check out this thread and search boards for ADDPRINTERCONNECTION

http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=110107&page=0&view=collapsed&sb=5&o=&fpart=1

From what you're asking, you just want a simple script for each group? for one printer to be added? If so, create a group of users for each printer and add users to this printer group.

(My Script uses computer group membership using Function ComputerInGroup.udf, not user groups, so you'd need to modify the script that you'll find in the thread I posted above for users, not computers. Or try the simple script I posted here.)

This script has not been tested for syntax.

Code:

;****adds and sets default printer if printer does not exist
if InGroup('your_group_name')

$printer=('\\server\printershare')

if not PriMapState($printer)
$nul=AddPrinterConnection($printer)
endif

endif

;FUNCTION PriMapState v1.1
;
;AUTHOR Lonkero (Jooel.Nieminen@gwspikval.com)
;
;ACTION Checks for existent networkprinter connection
;
;SYNTAX PriMapState(PRINTER)
;
;PARAMETERS PRINTER
; Printers name to be checked
;
;RETURNS 1 if printer connected
; 2 if printer is default
; nothing if not connected
;
;REMARKS code for w9x adapted from BrianTX
;
;DEPENDENCIES none
;
;EXAMPLE if not PriMapState('\\server\printer1')
; "printer not connected!"
; end
;
function PriMapState($_Pri)
if @inwin=1
if len(readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices",$_Pri))
if split(readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),",")[0]=$_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