#114769 - 2004-02-25 03:13 PM
Re: Add network printer
|
jering
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
|
|
|
|
#114771 - 2004-02-25 09:44 PM
Re: Add network printer
|
jering
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
|
|
|
|
#114773 - 2004-02-25 10:05 PM
Re: Add network printer
|
Kdyer
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
|
Top
|
|
|
|
#114774 - 2004-02-25 10:11 PM
Re: Add network printer
|
jering
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
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
|
|
|
|
#114778 - 2004-02-25 10:26 PM
Re: Add network printer
|
jering
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
|
|
|
|
#114780 - 2004-02-25 10:30 PM
Re: Add network printer
|
jering
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
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
|
|
|
|
#114783 - 2004-02-25 10:36 PM
Re: Add network printer
|
jering
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
|
|
|
|
#114786 - 2004-02-26 02:04 AM
Re: Add network printer
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 369 anonymous users online.
|
|
|