JohnLennon
(Fresh Scripter)
2006-02-28 01:28 PM
Add new printer

Instead of move a printer (wich i found on these forums) i'm looking for a script to add a new printer includes the driver. Also with possibility to configure the settings.
Can anyone help me ? I looked everywhere, but even in the usermanuel i can't find the solution.

ps.

i want to add this script for my RIS installation (unattended for winXP)


LonkeroAdministrator
(KiX Master Guru)
2006-02-28 01:56 PM
Re: Add new printer

add printer?
is it local printer?
if yes, it is installed automatically, no?
if not, use addprinterconnection() as descriped in manual.


JohnLennon
(Fresh Scripter)
2006-02-28 01:57 PM
Re: Add new printer

It is a networkprinter. If i use addprinterconnection() how can i link it to his IP ?

LonkeroAdministrator
(KiX Master Guru)
2006-02-28 02:06 PM
Re: Add new printer

you are not using printer server but directly connecting to the printers port?

Benny69
(MM club member)
2006-02-28 02:07 PM
Re: Add new printer

Hi JohnLennon and welcome to korg,
Not sure if this is what you are looking for but maybe it’s a start. For these functions to work you must have the printer drivers already installed.

Code:

$OperatingSystem = @PRODUCTTYPE
AddPrinter("\\ServerName\PrinterShareName")
SetDefPrinter("\\ServerName\PrinterShareName")

Function AddPrinter($PrinterLocation)
If InStr($OperatingSystem,"Server")
$WshNetwork = CreateObject("WScript.Network")
$WshNetwork.AddWindowsPrinterConnection($PrinterLocation)
Else
$= AddPrinterConnection($PrinterLocation)
EndIf
EndFunction

Function SetDefPrinter($PrinterLocation)
If InStr($OperatingSystem,"Server")
$WshNetwork = CreateObject("WScript.Network")
$WshNetwork.SetDefaultPrinter($PrinterLocation)
Else
$= SetDefaultPrinter($PrinterLocation)
EndIf
EndFunction



LonkeroAdministrator
(KiX Master Guru)
2006-02-28 02:12 PM
Re: Add new printer

benny, your udf's are just wscript versions of the inbuilt kixtart functions and nobody should use them for anything but testing because of the extra overheat, right?

but if he is talking about IP printer, he can use instead of the addprinterconnection() this udf by Allen:
http://www.kixtart.org/UDF/UDF_lister.php?what=post&code=83350


Benny69
(MM club member)
2006-02-28 02:25 PM
Re: Add new printer

JohnLennon,
Jooel will be a much better guide for you and will be able to give you better advice.


JohnLennon
(Fresh Scripter)
2006-02-28 02:36 PM
Re: Add new printer

Jooel,
if i look at the script (from Allen) i see the green text, but what must i change to config it to my personal settings ?

This line:
$=WriteValue($IPPrinterKey,"IPAddress","$Port","REG_SZ")

or:
; IPAddress (xxx.xxx.xxx.xxx)


LonkeroAdministrator
(KiX Master Guru)
2006-02-28 03:10 PM
Re: Add new printer

it's udf and what you need to do is place the whole code somewhere in your script file.
normally it's right at the end.
then you use it like any kixtart's internal function.
the examples section in the green... the first line probably is the way you are wanting to do it.

benny, sorry if I depressed your helping will...


Benny69
(MM club member)
2006-02-28 03:15 PM
Re: Add new printer

na, you da man!

JohnLennon
(Fresh Scripter)
2006-03-01 10:07 AM
Re: Add new printer

The lines after the ";" symbol doesn't count ?

LonkeroAdministrator
(KiX Master Guru)
2006-03-01 11:54 AM
Re: Add new printer

; is a single line comment symbol.
so each line starting with it (they are colored green in the post) are informatic comments.


JohnLennon
(Fresh Scripter)
2006-03-01 12:53 PM
Re: Add new printer

o.k. so it doesn't matter if i delete those lines

LonkeroAdministrator
(KiX Master Guru)
2006-03-01 02:12 PM
Re: Add new printer

well, basically not.
but you should not.
if you place the whole code right after your script, at the very end, they are not bothering you at all but they do inform you about the usability and such of the UDF.

so, for your own good, you should just simply copy everything from the first line that says:
;function

to the very last:
endfunction

just as it is into your script file.
unmodified and 100% functional, tested and proved code.


Mart
(KiX Supporter)
2006-03-01 02:48 PM
Re: Add new printer

Or just paste the entire UDF code into a separate file, save the file in the same dir your script is or create a functions dir inside the dir your script is in (I prefer the second option) and call the function once at the beginning of your script. This way they are not in your primary script and can still be used but they just don't make your script that long.
This way you will also get a nice clean separation between your code and code somebody else wrote.

Code:

Call @scriptdir + "\SomeFunction.kix"

All other ode goes here



or

Code:

Call @scriptdir + "\functions\SomeFunction.kix"

All other ode goes here