#Include <File.au3>
#Include <Array.au3>
#include <GUIConstants.au3>

global $data
$file1 = FileOpen ("Printer.txt", 0)
If $file1 = -1 Then
	MsgBox(0, "Fehlende Daten!", "Printer.txt scheint zu fehlen!")
	Exit
EndIf
$zeile = 1
while 1
	$read = FileReadLine($file1, $zeile)
		If $read = "" then ExitLoop
		$data = $data & $read & "|"
		$zeile += 1
WEnd

;Create GUI	
GUICreate("Druckerverbindung", 280, 280)		
GUICtrlCreateLabel("Netzwerk-Drucker verbinden", 20,15,800)
GUICtrlSetFont (-1, 9.5, 800, 0, "Arial")
GUICtrlCreateLabel("Gebäude:",20,40)
GUICtrlCreateLabel("Etage:",20,80)
GUICtrlCreateLabel("Raum:",20,120)
GUICtrlCreateLabel("Gerät:",20,160)
$building = GUICtrlCreateCombo ("-bitte wählen-",20,55,240)
$floor = GUICtrlCreateCombo ("-bitte wählen-",20,95,240)
$room = GUICtrlCreateCombo ("-bitte wählen-",20,135,240)
$typ = GUICtrlCreateCombo ("-bitte wählen-",20,175,240)
GUICtrlSetData(-1, $data)
$default = GUICtrlCreateCheckbox ("Als Standarddrucker festlegen", 20,205,200)
$button1 = GUICtrlCreateButton("Installieren",40,235,200)
GUISetState()	
	
While 1
$msg = GUIGetMsg()
Select
	Case $msg = $GUI_EVENT_CLOSE ;Close Programm
	GUIDelete("Druckerverbindung")
	ExitLoop

	Case $msg = $button1 ;Connect to Printer
	$command1 = ('rundll32 printui.dll,PrintUIEntry /in /n "\\demonas11\' & GUICtrlRead($typ) & '"')
	$command2 = ('rundll32 printui.dll,PrintUIEntry /y /n "\\demonas11\' & GUICtrlRead($typ) & '"')
		If GUICtrlRead($default) = $gui_checked Then
		RunWait(@comspec & ' /c ' & $command1,'', @SW_HIDE)
		ProcessWaitClose ( "rundll32.exe")
		RunWait(@comspec & ' /c ' & $command2,'', @SW_HIDE)
	else
		RunWait(@comspec & ' /c ' & $command1,'', @SW_HIDE)
	Endif
EndSelect
WEnd	
Exit				