Page 2 of 2 <12
Topic Options
#114769 - 2004-02-25 03:13 PM Re: Add network printer
jering Offline
Fresh Scripter
*

Registered: 2004-02-25
Posts: 17
Quote:

Code:
Function Name_of_UDF($parameter 1, $parameter2, optional $parameter3)

EndFunction





This will never work, This isn't a function at all!

Please read the whole thread again.

First: Search the board for addprinter() and don't modify this UDF..
Second: Tell us how your other printers are connected, Do you use a printserver?? They are connected to some regular PC`s, so then I just use the ADDPRINTERCONNECTION ("printer name"), but since this printer only have an IP I want to use the UDF...
Read the URL I have posted before...

Etc.







(Haven`t anyone got a *.kix with a UDF code, so I could use it as an example?)


Edited by jering (2004-02-25 03:17 PM)

Top
#114770 - 2004-02-25 03:51 PM Re: Add network printer
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22298
Loc: OK
argh!
if you looked at the code (and finally the doc in faq) it has examples.
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=83350&page=8&view=collapsed&sb=1&o=&fpart=1

can't understand what is so hard in it?
if you just wanna test the examples, uncomment one of them to see what happens.

I still beg you to read the friendly faq.
_________________________
!

download KiXnet

Top
#114771 - 2004-02-25 09:44 PM Re: Add network printer
jering Offline
Fresh Scripter
*

Registered: 2004-02-25
Posts: 17
Now I got it clearer. I think it was the semicolons that confused me.

But please have look:
Code:
 http://home.c2i.net/jering/diverse 




Please download the 4 files:
AddPrint.kix
AddPrint2.kix
test.bat
test.kix

I`m not getting any error message. But when I run the script my printer does not install. Now I`m testing the script locally on my computer. I have connected a HP LaserJet 5L to the LPT port (It installed itself in Win XP, but I removed it to try to install it with the script)
First I tried with the AddPrint file, but realised that I must have the code with, so it should work like I`ve done it in AddPrint2.kix? Didn`t work for me though...


Any suggestions?


Edited by jering (2004-02-25 10:28 PM)

Top
#114772 - 2004-02-25 10:01 PM Re: Add network printer
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22298
Loc: OK
well, you do it the hard way but basically, this works.
now it's the same as if the udf file WAS INSIDE YOUR SCRIPT FILE.
which is the basic way.
now, in your TEST.KIX use the udf.

there is no need for any bat files.
_________________________
!

download KiXnet

Top
#114773 - 2004-02-25 10:05 PM Re: Add network printer
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Quote:

But please have look:
http://home.c2i.net/jering/diverse/

Please download the 3 files:
AddPrint.kix
test.bat
test.kix





Can you not post code here? If your server is down, how can you/we help anybody else that may have similar issues?

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#114774 - 2004-02-25 10:11 PM Re: Add network printer
jering Offline
Fresh Scripter
*

Registered: 2004-02-25
Posts: 17
Quote:


Can you not post code here? If your server is down, how can you/we help anybody else that may have similar issues?

Kent





Done.

Top
#114775 - 2004-02-25 10:15 PM Re: Add network printer
jering Offline
Fresh Scripter
*

Registered: 2004-02-25
Posts: 17
Quote:

well, you do it the hard way but basically, this works.
now it's the same as if the udf file WAS INSIDE YOUR SCRIPT FILE.
which is the basic way.
now, in your TEST.KIX use the udf.

there is no need for any bat files.





Ok, I see. To test the script I use the dos-promt and go to c:\kix and write "kix 32 AddPrint" and as you can see (home.c2i.net/jering/diverse/command.JPG) the script runs with no errors, but the printer is still not added.

Top
#114776 - 2004-02-25 10:21 PM Re: Add network printer
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22298
Loc: OK
k, now you need to ask why it's not mapped?
still waiting for your script (the one that uses addprinter udf) to be posted here.

specially when your filetype bindings force to execute the script instead of viewing it.
_________________________
!

download KiXnet

Top
#114777 - 2004-02-25 10:25 PM Re: Add network printer
Co Offline
MM club member
***

Registered: 2000-11-20
Posts: 1338
Loc: NL
Quote:

Quote:

Can you not post code here? If your server is down, how can you/we help anybody else that may have similar issues?

Kent







Done.




Euh... Where is your code??

It is very easy.. click code at Instant UBB Code and paste your code between {code} {/code}
_________________________
Co


Top
#114778 - 2004-02-25 10:26 PM Re: Add network printer
jering Offline
Fresh Scripter
*

Registered: 2004-02-25
Posts: 17
Quote:

k, now you need to ask why it's not mapped?
still waiting for your script (the one that uses addprinter udf) to be posted here.

specially when your filetype bindings force to execute the script instead of viewing it.




home.c2i.net/jering/diverse/AddPrint3.kix <-- Shouldn`t that work? Can I view the commands while they`re being executed?

Top
#114779 - 2004-02-25 10:30 PM Re: Add network printer
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22298
Loc: OK
k, now I need to ask you sit back for a second or better... for 2 seconds.
really think what you are wanting to do and what you are wanting to do to get it done.

first, you need to slow down and do as adviced.
we can't go around your will, we have life's too.
if you really don't want to get any help, please say so.

otherwise I need to ask you to really listen and learn.
_________________________
!

download KiXnet

Top
#114780 - 2004-02-25 10:30 PM Re: Add network printer
jering Offline
Fresh Scripter
*

Registered: 2004-02-25
Posts: 17
Quote:

Euh... Where is your code??

It is very easy.. click code at Instant UBB Code and paste your code between {code} {/code}




Now then?

Top
#114781 - 2004-02-25 10:33 PM Re: Add network printer
jering Offline
Fresh Scripter
*

Registered: 2004-02-25
Posts: 17
Quote:

k, now I need to ask you sit back for a second or better... for 2 seconds.
really think what you are wanting to do and what you are wanting to do to get it done.

first, you need to slow down and do as adviced.
we can't go around your will, we have life's too.
if you really don't want to get any help, please say so.

otherwise I need to ask you to really listen and learn.




Ok, now I just want to make the script install my local printer on LPT1 to see that it works. If it does, I`ll try to use it to install the network printer.

Top
#114782 - 2004-02-25 10:35 PM Re: Add network printer
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22298
Loc: OK
can't say what is going on as can't see your script.
_________________________
!

download KiXnet

Top
#114783 - 2004-02-25 10:36 PM Re: Add network printer
jering Offline
Fresh Scripter
*

Registered: 2004-02-25
Posts: 17
Code:
function UDFTemplateDemo($var1, $var2, optional $var3, optional $var4)
; DIM all variables used inside the UDF
dim $helpvar, $helparray[4]

; set the default return value
$udftemplate=''

; perform checks on all input parameters to make sure they fit the requirements
; if necessary, exit the UDF and return an error code

; var1 must be a string, thus convert to string if it is not a string
if vartype($var1)<>8
$var1=''+$var1
endif

; var 2 must be an integer, thus convert var2 into an integer
$var2=val($var2)

; var3 must be a string, thus convert to string if it is not a string
; however, it is also an optional parameter, thus we set it to a default value
; if the parameter is not provided
if vartype($var3)
if vartype($var3)<>8
$var3=''+$var3
endif
else
; parameter has not been provided, thus set default value
$var3='default value'
endif

; var 4 must be an integer, if it is provided
if vartype($var4)
if vartype($var4)<>2 and vartype($var4)<>3
; variable is not an integer, thus exit with 'Invalid Parameter' error code
exit 87
endif
else
; parameter has not been provided, thus set default value
$var4=0
endif

? 'Content of variable $var1 = '+$var1
? 'Variable type of $var2 = '+vartype($var2)+' - '+vartypename($var2)
? 'Content of variable $var3 = '+$var3

; demonstrating bit-wise decisions
for $helpvar=0 to 4
if $var4 & ($helpvar+1)
$helparray[$helpvar]='Bit '+($helpvar+1)+' is set'
else
$helparray[$helpvar]='Bit '+($helpvar+1)+' is not set'
endif
next

$udftemplate=join($helparray,@CRLF)

; UDF ran successfully, thus set exit code to 0
; this is optional, however it will reset a potentially
; existing @ERROR back to 0
exit 0
endfunction

function AddPrinter($Port,$PrinterType,optional $DriverInf,optional $PrinterDesc,optional $remotepc,optional $Default)
Dim $quitloop,$IPPrinterKey,$PrinterCMD
$AddPrinter=0
if not left($Port,2)="\\"
if $Driverinf=""
$DriverInf="%windir%\inf\ntprint.inf"
endif
if not exist($DriverInf)
Exit -3
endif
shell '%comspec% /c type "$driverinf">%temp%\addprinter.txt'
if open(3,"%temp%\addprinter.txt",0)=0
$quitloop=0
while @error=0 and $quitloop=0
$line=readline(3)
$quitloop=instr($line,$PrinterType)
loop
$=close(3)
if $quitloop=0
exit -2
endif
else
Exit -3
endif
endif
if $PrinterDesc=""
$PrinterDesc=$PrinterType
endif
if $remotepc=""
$remotepc='\\'+ @wksta
else
if not left($remotepc,2)="\\"
$remotepc='\\' + $remotepc
endif
endif

select
case left($Port,2)="\\"
$printserver=1
$printerdesc=$port
case instr($Port,".")
$IPPrinterKey = '$remotepc\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_' +$Port
if not keyexist($IPPrinterKey)
$=Addkey($IPPrinterKey)
$=WriteValue($IPPrinterKey,"Protocol","00000001","REG_DWORD")
$=WriteValue($IPPrinterKey,"Version","00000001","REG_DWORD")
$=WriteValue($IPPrinterKey,"HostName","", "REG_SZ")
$=WriteValue($IPPrinterKey,"IPAddress","$Port","REG_SZ")
$=WriteValue($IPPrinterKey,"HWAddress","","REG_SZ")
$=WriteValue($IPPrinterKey,"PortNumber","00009100","REG_DWORD")
$=WriteValue($IPPrinterKey,"SNMP Community","public","REG_SZ")
$=WriteValue($IPPrinterKey,"SNMP Enabled","00000001","REG_DWORD")
$=WriteValue($IPPrinterKey,"SNMP Index","00000001","REG_DWORD")
endif
$objects=GetObject("winmgmts:{impersonationLevel=impersonate}!"+$remotepc+"\root\cimv2")
if not @error=0
exit -4
endif
$services=$objects.ExecQuery('Select * from Win32_Service WHERE Name = "Spooler"')
for each $spooler in $services
$=execute('$$=$$spooler.stopservice()')
next
sleep 1
for each $spooler in $services
$=execute('$$=$$spooler.startservice()')
next
$port='IP_$port'
case ucase(left($Port,3))="LPT" or ucase(left($Port,3))="COM"
if not right($port,1)=":"
$Port=$port+":"
endif
if not val(left(right($port,2),1))>=1
exit -1
endif
case ucase(left($Port,4))="FILE"
if not right($port,1)=":"
$Port=$port+":"
endif
case 1
exit -1
endselect
if not $Printserver=1
$printercmd='rundll32 printui.dll,PrintUIEntry /if /b "$printerdesc" /c "$remotepc" ' +
'/f "$driverinf" /r "$port" /m "$Printertype" /z /u '
Shell $printercmd
else
if not addprinterconnection($port)=0
exit @error
endif
endif
if $default=1
if not SetDefaultPrinter($PrinterDesc)=0
exit @error
endif
endif
$AddPrinter=1
endfunction

function $=Addprinter("LPT1","HP LaserJet 5L",,"Gull")
endfunction


Top
#114784 - 2004-02-25 10:40 PM Re: Add network printer
Co Offline
MM club member
***

Registered: 2000-11-20
Posts: 1338
Loc: NL
Jering,

Do you want Help or not???
I have the idea you are making a fool of us .

The people on this board wants to help you. We all wanna do it and we do it for free because we love Kix..

But if you don't help us to help you, you really are pissing me off!

So, please read this thread do what people ask, read some other topic in the forums. Maybe after doing that you know how we comunnicate with each other...

Read the FAQ forum and the manual... and tell us all we need to know..

_________________________
Co


Top
#114785 - 2004-02-25 10:40 PM Re: Add network printer
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22298
Loc: OK
no, you are still trying to write your OWN UDF!
you have been asked to look at HOW TO USE AN UDF.
can't understand which word is way too high.

using and writing is totally different thing (at least this far I thought so)
so I again ask you to look at the HOW TO USE UDF's thread in the FAQ

you are not asked to create your own udf.
you are asked to use one written FOR YOU
it's already there, don't mind it.
just use it.
_________________________
!

download KiXnet

Top
#114786 - 2004-02-26 02:04 AM Re: Add network printer
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11554
Loc: CA
Hi jering,

Please do the following and hopefully it should work for you.

If you have not already done so, please do read the FAQs on the UDF usage. Reading the manual that ships with KiXtart will also show you how to use the script language some.

Anyways, copy the following code from here and paste it into NOTEPAD (if it copies all onto a single line, then copy it into WORDPAD first, then from WORDPAD copy it and then paste it into NOTEPAD and save the file as C:\KIX\GULLPRINTER.KIX

Then from a DOS Console (cmd.exe) Run the following (assuming that KiXtart v4.22 is in the C:\KIX folder as KIX32.EXE)

C:\KIX\KIX32.EXE C:\KIX\GULLPRINTER.KIX

DO NOT CHANGE - ADD - OR OTHERWISE MODIFY THE FILE IN ANYWAY

A UDF is called, you don't modify any part of the UDF.

Code:
Break On
Dim $RC

$RC = Addprinter("LPT1","HP LaserJet 5L",,"Gull")
fnCOMErr(@ERROR)
? 'Adding Printer was: ' +@ERROR +' '+@SERROR
 

function AddPrinter($Port,$PrinterType,optional $DriverInf,optional $PrinterDesc,optional $remotepc,optional $Default)
Dim $quitloop,$IPPrinterKey,$PrinterCMD
$AddPrinter=0
if not left($Port,2)="\\"
if $Driverinf=""
$DriverInf="%windir%\inf\ntprint.inf"
endif
if not exist($DriverInf)
Exit -3
endif
shell '%comspec% /c type "$driverinf">%temp%\addprinter.txt'
if open(3,"%temp%\addprinter.txt",0)=0
$quitloop=0
while @error=0 and $quitloop=0
$line=readline(3)
$quitloop=instr($line,$PrinterType)
loop
$=close(3)
if $quitloop=0
exit -2
endif
else
Exit -3
endif
endif
if $PrinterDesc=""
$PrinterDesc=$PrinterType
endif
if $remotepc=""
$remotepc='\\'+ @wksta
else
if not left($remotepc,2)="\\"
$remotepc='\\' + $remotepc
endif
endif

select
case left($Port,2)="\\"
$printserver=1
$printerdesc=$port
case instr($Port,".")
$IPPrinterKey = '$remotepc\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_' +$Port
if not keyexist($IPPrinterKey)
$=Addkey($IPPrinterKey)
$=WriteValue($IPPrinterKey,"Protocol","00000001","REG_DWORD")
$=WriteValue($IPPrinterKey,"Version","00000001","REG_DWORD")
$=WriteValue($IPPrinterKey,"HostName","", "REG_SZ")
$=WriteValue($IPPrinterKey,"IPAddress","$Port","REG_SZ")
$=WriteValue($IPPrinterKey,"HWAddress","","REG_SZ")
$=WriteValue($IPPrinterKey,"PortNumber","00009100","REG_DWORD")
$=WriteValue($IPPrinterKey,"SNMP Community","public","REG_SZ")
$=WriteValue($IPPrinterKey,"SNMP Enabled","00000001","REG_DWORD")
$=WriteValue($IPPrinterKey,"SNMP Index","00000001","REG_DWORD")
endif
$objects=GetObject("winmgmts:{impersonationLevel=impersonate}!"+$remotepc+"\root\cimv2")
if not @error=0
exit -4
endif
$services=$objects.ExecQuery('Select * from Win32_Service WHERE Name = "Spooler"')
for each $spooler in $services
$=execute('$$=$$spooler.stopservice()')
next
sleep 1
for each $spooler in $services
$=execute('$$=$$spooler.startservice()')
next
$port='IP_$port'
case ucase(left($Port,3))="LPT" or ucase(left($Port,3))="COM"
if not right($port,1)=":"
$Port=$port+":"
endif
if not val(left(right($port,2),1))>=1
exit -1
endif
case ucase(left($Port,4))="FILE"
if not right($port,1)=":"
$Port=$port+":"
endif
case 1
exit -1
endselect
if not $Printserver=1
$printercmd='rundll32 printui.dll,PrintUIEntry /if /b "$printerdesc" /c "$remotepc" ' +
'/f "$driverinf" /r "$port" /m "$Printertype" /z /u '
Shell $printercmd
else
if not addprinterconnection($port)=0
exit @error
endif
endif
if $default=1
if not SetDefaultPrinter($PrinterDesc)=0
exit @error
endif
endif
$AddPrinter=1
endfunction

Function fnCOMErr($lErr)
If $lErr<0 $lErr=VAL("&"+Right(DecToHex($lErr),4)) EndIf
Exit $lErr
Endfunction


Top
#114787 - 2004-02-26 03:26 AM Re: Add network printer
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11162
Loc: Boston, MA, USA
jering: I'm still confused why you want to connect all computers directly to the network printer instead of routing all print jobs through a print server, which you obviously have? This would ease printer administration tremendously as you have to update drives and make configuration changes only on the print server and not all computers?

You do realize that even if the printer is connected diretly to the network, you can still have people send print jobs to a print server and the print server then forwards the jobs to the actual printer?
_________________________
There are two types of vessels, submarines and targets.

Top
Page 2 of 2 <12


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

Who's Online
1 registered (Allen) and 171 anonymous users online.
Newest Members
FlyHorton, mschwj, Barchester, Evgeniy, kvanacker
17498 Registered Users

Generated in 0.093 seconds in which 0.048 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org