Jump to content

Script problems with GUI interface


gorbisloth
 Share

Recommended Posts

I'm working on a little program to update some info in the unattend xml file for doing Win7 installs. It's fairly simple, a pop up window prompts for the computer name, and the username, password for the account to add it to the domain. If the fields aren't blank it reads the current sysprep file and replaces the temporary text with the user input. If the fields are left blank it is supposed to just throw up an error window and exit. Right now my If statement is failing to acknowledge that there is any input in the fields so it's always dropping to the error window. I had it working earlier today but after trying to make some further adjustments to the script it stopped working.

I can't figure out why it's not working. I'm getting values returned for the variables but it's saying I'm not. I'd like to figure out what I messed up. Also one other thing I'd like is if some of the fields are left blank i'd like it to leave the primary window open for the user to complete the form instead of just exiting.

I'm sure there's a cleaner way of doing this but I'm new.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Sysprep = "C:\Windows\Panther\unattend.xml"
Global $sIni = "c:\temp\TAG.ini"
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_ComputerSystemProduct", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
#Region ### START Koda GUI section ### Form=c:\users\whalmich\desktop\scripts\koda\forms\updatexmlinput.kxf
$Form1_1 = GUICreate("Add to Domain Info", 576, 404, 209, 138)
$PCName = GUICtrlCreateInput(IniRead($sIni, 'HW Info', 'Service Tag', ''), 256, 144, 121, 21)
GUICtrlCreateLabel("Enter Computer Name", 112, 144, 108, 17)
$User = GUICtrlCreateInput("", 256, 184, 121, 21)
GUICtrlCreateLabel("Enter Username", 112, 184, 80, 17)
$Password = GUICtrlCreateInput("", 256, 224, 121, 21, 0x0020)
GUICtrlCreateLabel("Enter Password", 112, 224, 78, 17)
$okbutton = GUICtrlCreateButton("Ok", 272, 336, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
 
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $okbutton
  If  GUICtrlRead($PCName) = 0 or GUICtrlRead($User) = 0 or GUICtrlRead($Password) = 0 Then
    $Flag = 0
    MsgBox(16, "Error", "You must supply a Computer Name, User Name and Password")
    Exit
   Else
     $Flag = 1
    While $Flag = 1
   If @error = -1 Then ExitLoop
    $Text = FileRead($Sysprep,FileGetSize($Sysprep))
    $Text = StringReplace($Text, "%ComputerName%", GUICtrlRead($PCname))
    $Text = StringReplace($Text, "%UserName%", GUICtrlRead($User))
    $Text = StringReplace($Text, "%Password%", GUICtrlRead($Password))
    FileDelete($Sysprep)
    FileWrite($Sysprep,$Text)
    FileClose($Sysprep)
    Exit
    Wend
 
  EndIf
EndSwitch
WEnd
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...