good points witto,
here is the modified code:
Code:

Break On
$System = CreateObject("Kixtart.System")
If Not $System
$nul= MessageBox("KiXforms Not Initiated. This Script Will Now Close.","Error",16)
Quit()
EndIf

$Form = $System.Form()
$Form.Text = "St. Matthew School Computer Network - Admin Site Printer Install"
$Form.Width = 600
$Form.Height = 600
$Form.BackColor = $Form.RGB(255,255,0)

$Panel = $Form.Controls.Add("Panel")
$Panel.Dock = "top" ;resize for your needs
$Panel.BackgroundImage = "\\s096-a0290-01\sch030$\printers\matthew.jpg"

$Instructions = $Form.Controls.Add("Label")
$Instructions.Height = 31
$Instructions.Left = 10
$Instructions.TextAlign = 32 ;Center Text in Label
$Instructions.Text = "Please wait while I determine which printers you are already connected to..."
$Instructions.Top = 135
$Instructions.Width = $Form.ClientWidth-20

$Listbox = $Form.Controls.Add("Listbox")
$Listbox.Height = 150
$Listbox.Left = 280
$Listbox.Top = 175
$Listbox.Width = 250

$DefPrintersRadioButton = $Form.Controls.Add("RadioButton")
$DefPrintersRadioButton.Left = 10
$DefPrintersRadioButton.Top = $Listbox.Bottom+10
$DefPrintersRadioButton.Text = "Use Current Printer Settings"
$DefPrintersRadioButton.Width = 150
$DefPrintersRadioButton.Checked = "True"
$DefPrintersRadioButton.OnClick = "CheckPrinterRadioButtons()"

$ModPrintersRadioButton = $Form.Controls.Add("RadioButton")
$ModPrintersRadioButton.Left = 10
$ModPrintersRadioButton.Top = $DefPrintersRadioButton.Bottom+10
$ModPrintersRadioButton.Text = "Modify Printer Settings"
$ModPrintersRadioButton.Width = 150
$ModPrintersRadioButton.OnClick = "CheckPrinterRadioButtons()"

$PrintersGroupBox = $Form.Controls.Add("GroupBox")
$PrintersGroupBox.Left = $ModPrintersRadioButton.Right+10
$PrintersGroupBox.Top = $ModPrintersRadioButton.Top
$PrintersGroupBox.Height = 85
$PrintersGroupBox.Width = $Form.ClientWidth-180
$PrintersGroupBox.Text = "Default Install Printer"

$ComputerLabRadioButton = $PrintersGroupBox.Controls.Add("RadioButton")
$ComputerLabRadioButton.Left = 20
$ComputerLabRadioButton.Top = 20
$ComputerLabRadioButton.Height = 20
$ComputerLabRadioButton.Width = 20
$ComputerLabRadioButton.Enabled = "False"
$ComputerLabRadioButton.OnClick = "CheckComputerLabRadioButton()"

$ComputerLabCheckBox = $PrintersGroupBox.Controls.Add("CheckBox")
$ComputerLabCheckBox.Left = $ComputerLabRadioButton.Right+20
$ComputerLabCheckBox.Top = $ComputerLabRadioButton.Top
$ComputerLabCheckBox.Height = 20
$ComputerLabCheckBox.Width = $PrintersGroupBox.Width-$ComputerLabCheckBox.Left-10
$ComputerLabCheckBox.Text = "Computer Lab Printer"
$ComputerLabCheckBox.Enabled = "False"
$ComputerLabCheckBox.OnClick = "CheckComputerLabCheckBox()"

$LibraryPrinterRadioButton = $PrintersGroupBox.Controls.Add("RadioButton")
$LibraryPrinterRadioButton.Left = 20
$LibraryPrinterRadioButton.Top = $ComputerLabRadioButton.Bottom
$LibraryPrinterRadioButton.Height = 20
$LibraryPrinterRadioButton.Width = 20
$LibraryPrinterRadioButton.Enabled = "False"
$LibraryPrinterRadioButton.OnClick = "CheckLibraryPrinterRadioButton()"

$LibraryPrinterCheckBox = $PrintersGroupBox.Controls.Add("CheckBox")
$LibraryPrinterCheckBox.Left = $LibraryPrinterRadioButton.Right+20
$LibraryPrinterCheckBox.Top = $LibraryPrinterRadioButton.Top
$LibraryPrinterCheckBox.Height = 20
$LibraryPrinterCheckBox.Width = $PrintersGroupBox.Width-$LibraryPrinterCheckBox.Left-10
$LibraryPrinterCheckBox.Text = "Library Printer"
$LibraryPrinterCheckBox.Enabled = "False"
$LibraryPrinterCheckBox.OnClick = "CheckLibraryPrinterCheckBox()"

$OfficePrinterCheckBox = $PrintersGroupBox.Controls.Add("CheckBox")
$OfficePrinterCheckBox.Left = $LibraryPrinterRadioButton.Right+20
$OfficePrinterCheckBox.Top = $LibraryPrinterCheckBox.Bottom
$OfficePrinterCheckBox.Height = 20
$OfficePrinterCheckBox.Width = $PrintersGroupBox.Width-$OfficePrinterCheckBox.Left-10
$OfficePrinterCheckBox.Text = "Office Printer"
$OfficePrinterCheckBox.Enabled = "False"

$Exit = $Form.Controls.Add("Button")
$Exit.Cancel = "True"
$Exit.Default = "True"
$Exit.Height = 31
$Exit.Left = 10
$Exit.Text = "Click Here To Close This Window"
$Exit.Top = $PrintersGroupBox.Bottom+10
$Exit.Width = $Form.ClientWidth-20
$Exit.OnClick = "ExitButton()"

$Form.Center
$Form.Show

$nul = GetDefaultPrinter()
EnumPrinters()
$Instructions.Text = "Your printers are listed. Now you can add extra printers and change the default."

While $Form.Visible
$nul = Execute($Form.DoEvents)
Loop
Exit 1

Function GetDefaultPrinter()

;FUNCTION GetDefaultPrinter()
;
;AUTHOR Jochen Polster (jochenDOTpolsterATgmxDOTnet)
;
;VERSION 1.0
;
;VERSION HISTORY 1.0 2004/04/28 Initial release
;
;ACTION Retrieves the current default Printer
;
;SYNTAX GetDefaultPrinter()
;
;PARAMETERS none
;
;REMARKS won't work with 9x OS
;
;RETURNS The current Users default Printer
;
;DEPENDENCIES None !
;
;EXAMPLES $default = GetDefaultPrinter

$GetDefaultPrinter = Join(Split(ReadValue("HKEY_USERS\"+@sid+"\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),',',1),'')
$Listbox.additem("Default Printer = "+$GetDefaultPrinter)
;Create blank space between default printer listing and the listing of all printers.
$Listbox.additem("")

EndFunction

Function EnumPrinters()

;Writes all printer to a file.
;$array=printerlist()
;$rc = Open (1, "c:\installedprinters.txt", 5)
;For Each $printer in $array
; $rc = WriteLine (1, $printer + " is installed on: " + @WKSTA + @CRLF)
;Next
;$rc = Close(1)

;DISPLAY LOCAL AND NETWORKED PRINTERS

;shows the printers on your screen.
$array=printerlist()
For Each $printer in $array
$Listbox.additem("Printer = "+$printer)
Next

EndFunction

Function PrinterList(optional $remotepc, optional $displaymode)

;Function:
; PrinterList()
;
;Author:
; Allen Powell (Al_Po)
;
;Version:
; 1.3.1 (2006/05/10 fixed error detecting Print Servers sharing IP Printers)
;
;Revisions
; 1.3.0 (2005/10/21 added options to distinguish local or remote printers)
; 1.2.0 (2005/07/19 optimized code)
; 1.1.0 (2004/08/09 undimmed variable fix)
; 1.0.0 (2003/06/26 Original)
;
;Action:
; Creates an array/list of Printers, and optionally their ports installed, on a local or remote computer.&n bsp;
;
;Syntax:
; Printerlist(optional $remotepc,optional $displaymode)
;
;Parameters:
; $RemotePC: (Optional)
; Remote Computer. If omitted defaults to localpc.
; $DisplayMode (Optional)
; 0 - show all printers, don't display port info (Default)
; 1 - show all printers, display port info
; 2 - show local printers, don't display port info
; 3 - show local printers, display port info
; 4 - show remote printers, don't display port info
; 5 - show remote printers, display port info
;Returns:
; Array of Printers
;
;Dependencies:
; WMI
;
;Example:
;
;break on
;$RC=Setoption("WrapAtEOL","on")
;
;$array=printerlist()
;for each $printer in $array
; ? $printer
;next
;
;Source:
Dim $service,$printer,$printers,$printerdesc[0],$counter,$portname,$printername
If $remotepc=""
$remotepc="."
EndIf
$Service = GetObject("winmgmts:\\" + $remotepc + "\root\cimv2")
If @error
Exit @error
EndIf
$Printers=$service.execquery ('select * from Win32_Printer')
For Each $printer in $printers
ReDim preserve $printerdesc[$counter]
If $displaymode & 1
$portname = "," + $printer.portname
EndIf
Select
Case $displaymode & 4 ;remote printers
If Left($printer.portname,2)="\\" Or Left($printer.name,2)=="\\"
$printername=$printer.name
EndIf
Case $displaymode & 2 ;local printers
If Left($printer.portname,2)<>"\\" And Left($printer.name,2)<>"\\"
$printername=$printer.name
EndIf
Case 1 ; all printers
$printername=$printer.name
EndSelect
If $printername<>""
$printerdesc[$counter]=$printername + $portname
$counter=$counter + 1
$printername=""
EndIf
Next
$PrinterList=$printerdesc

EndFunction

Function ExitButton()
SelectAPrinter()
Quit()
EndFunction

Function AddPrinter($Port,$PrinterType,optional $DriverInf,optional $PrinterDesc,optional $remotepc,optional $Default)
;Function:
; AddPrinter()
;
;Author:
; Allen Powell (Al_Po)
;
;Version:
; 1.0
;
;Action:
; Add IP,LPT, Or COM Printers locally Or remotely. Also, add PrintServer connections locally.
;
;Syntax:
; AddPrinter($Port,$PrinterType,optional $DriverInf,optional $PrinterDesc,optional $remotepc,optional $Default)
;
;Parameters:
; $Port: (required)
; IPAddress (xxx.xxx.xxx.xxx)
; LPT (LPT1:)
; COM (COM1:)
; PrintServer (\\server\printer)
; $PrinterType: (required)
; Descriptor of Printer within INF file
; Note: If using a PrintServer, $PrinterType value is ignored.
; $DriverInf: (Optional)
; Location And name of INF file containing print drivers
; Note: If omitted, attempts to Use default Windows Print Drivers
; $PrinterDesc: (Optional)
; Description of Printer
; Note: If ommitted, $PrinterDesc = PrinterType
; $RemotePC: (Optional)
; PC to install Printer/Drivers on. If omitted defaults to localpc.
; Note: Ignored If $Port is a PrintServer
; $Default: (Optional)
; 0 = Do Not Set as Default Printer (Default)
; 1 = Set as Default Printer
;
;Returns:
; 1 - Successful
; 0 - Failed
; If Failed sets @error to
; -4 - Error connecting to RemotePC
; -3 - Could Not Open/find INF file
; -2 - Could Not find $PrinterType in INF file
; -1 - Unrecognized Port
;
;Dependencies:
; Windows 2000 Professional And up
; rundll32 printui.dll,PrintUIEntry
;
;Examples:
;$=AddPrinter("192.168.1.1","Xerox DocumentCenter 555 PCL6","\\Server\PrinterDrives\Xerox\dc555pcl\dc555x.inf","Xerox Document Centre 55 5 PCL6 in Office",REMOTEPC,1)
;$=Addprinter("LPT1","HP LaserJet 8100 Series PS",,"HP8100 in IS(test)")
;$=AddPrinter("192.168.1.1","HP LaserJet 8100 Series PS",,"HP8100 in IS(test)",,1)
;$=AddPrinter('\\server\printer','_')
;Source:

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 SelectAPrinter()

If $ModPrintersRadioButton.Checked = "True"
Select
Case ($LibraryPrinterRadioButton.Checked = "False") And ($LibraryPrinterCheckBox.CheckState = -1)
AddPrinter("10.48.18.1","Lexmark T640","\\s096-a290-01\sch030$\printers\t640.inf","Library Printer",0)
Case ($LibraryPrinterRadioButton.Checked = "True") And ($LibraryPrinterCheckBox.CheckState = -1)
AddPrinter("10.48.18.1","Lexmark T640","\\s096-a290-01\sch030$\printers\t640.inf","Library Printer",1)
Case ($ComputerLabRadioButton.Checked = "False") And ($ComputerLabCheckBox.CheckState = -1)
AddPrinter("10.48.18.2","Lexmark T640","\\s096-a290-01\sch030$\printers\t640.inf","Computer Lab Printer",0)
Case ($ComputerLabRadioButton.Checked = "True") And ($ComputerLabCheckBox.CheckState = -1)
AddPrinter("10.48.18.2","Lexmark T640","\\s096-a290-01\sch030$\printers\t640.inf","Computer Lab Printer",1)
Case $OfficePrinterCheckBox.CheckState = -1
AddPrinter("10.48.18.3","Lexmark T640","\\s096-a290-01\sch030$\printers\t640.inf","Office Printer",0)
EndSelect
EndIf

EndFunction

Function CheckPrinterRadioButtons()

If $DefPrintersRadioButton.Checked = "True"
$ComputerLabRadioButton.Enabled = "True"
$LibraryPrinterRadioButton.Enabled = "True"
$ComputerLabCheckBox.Enabled = "True"
$LibraryPrinterCheckBox.Enabled = "True"
$OfficePrinterCheckBox.Enabled = "True"

$ComputerLabRadioButton.Checked = "True"
Else
$ComputerLabRadioButton.Enabled = "False"
$LibraryPrinterRadioButton.Enabled = "False"
$ComputerLabCheckBox.Enabled = "False"
$LibraryPrinterCheckBox.Enabled = "False"
$OfficePrinterCheckBox.Enabled = "False"

$ComputerLabRadioButton.Checked = "False"
$LibraryPrinterRadioButton.Checked = "False"

$ComputerLabCheckBox.CheckState = 0
$LibraryPrinterCheckBox.CheckState = 0
$OfficePrinterCheckBox.CheckState = 0
EndIf

EndFunction

Function CheckComputerLabRadioButton()

$LibraryPrinterRadioButton.Checked = "False"
$ComputerLabCheckBox.Checked = "True"

EndFunction

Function CheckLibraryPrinterRadioButton()

$ComputerLabRadioButton.Checked = "False"
$LibraryPrinterCheckBox.Checked = "True"

EndFunction

Function CheckComputerLabCheckBox()

If $LibraryPrinterRadioButton.Checked = "True"
$ComputerLabCheckBox.Checked = "True"
EndIf

EndFunction

Function CheckLibraryPrinterCheckBox()

If $ComputerLabRadioButton.Checked = "True"
$LibraryPrinterCheckBox.Checked = "True"
EndIf

EndFunction



Edited by benny69 (2006-10-02 12:26 AM)
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)