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