Jump to content

Can anyone help fix this?


Recommended Posts

I wrote this script to install some different software packages. Each software install is in its own function. I am using a Gui with OnEvent mode enabled. When I click the install button, it does nothing. What am I doing wrong? here is the code for the install button click.

Func InstallButtonclick()
    Select
        Case GUICtrlGetState($CUBRadio)= $GUI_CHECKED
            RunAsSet("user1", @ComputerName, "password")
        Case GUICtrlGetState($RWSRadio) = $GUI_CHECKED
            RunAsSet("user2", @ComputerName, "password2")
    EndSelect
        
        AircardInstall()
        FormsInstall()
        ScandallInstall()
        SnapshotInstall()
        RoadmapInstall()
        PrinterInstall()
        ScannerInstall()
        Sleep(3000)
        RunAsSet()
        GUICtrlSetState($LoadForm, @SW_HIDE)
        $DoneForm = GUICreate("Finished", 222, 138, 389, 272, $WS_POPUP)
        $DoneLabel = GUICtrlCreateLabel("All items installed successfully!", 24, 32, 180, 73)
        GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif")
        GUISetState($DoneForm, @SW_SHOW)
        Sleep(5000)
        GUISetState($DoneForm, @SW_HIDE)
        Exit
EndFunc

Hopefully someone can set me straight. I am trying to learn something new everyday.

Thanks!

Vito

Link to comment
Share on other sites

There is more to the 'STATE' of a control than just the 'IsChecked' status. So when you get the status by GuiCtrlGetStatus(), you need to test for that bit set among many:

Case BitAnd(GUICtrlGetState($CUBRadio), $GUI_CHECKED) <> 0oÝ÷ Øò¢çhmÁ©í¶ayn­¶­¶§ªç«ÊØZµìZrÚZ®Ú¶¬µ«n³­«­¢+Ø
Í
½¹Ñɽ±
½µµ¹ ÀÌØí]¥¹Q¥Ñ±°ÀÌØí]¥¹QáаÀÌØí
U   I¥¼°ÅÕ½Ðí%Í
¡­ÅÕ½ÐìÐÄì

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I tried what you recommended. I understand what you are saying. It still isn't working correctly though. Seems to skip all my functions and just exit out of the script. Would someone be willing to take a look at my full script?

Thanks!

Vito

Link to comment
Share on other sites

Would someone be willing to take a look at my full script?

Sure, just post it in AutoIt tags so it will be displayed in a scroll box.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

OK See what you can find wrong with this. I know it's not elegant, but I just need it to work. Thanks for the help!

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)
Opt("WinTitleMatchMode", 2)
Opt("TrayIconDebug", 1)

#Region ### START Koda GUI section ### Form=C:\Program Files\AutoIt3\SciTE\Koda\Forms\LoadForm.kxf
$LoadForm = GUICreate("New Machine Load Utility", 228, 333, 383, 180)
GUISetOnEvent($GUI_EVENT_CLOSE, "LoadFormClose")
$PlatformGroup = GUICtrlCreateGroup("Platform", 8, 8, 73, 73)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$CUBRadio = GUICtrlCreateRadio("CUB", 16, 32, 49, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetOnEvent(-1, "CUBRadioClick")
$RWSRadio = GUICtrlCreateRadio("RWS", 16, 56, 49, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetOnEvent(-1, "RWSRadioClick")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$AircardCheckbox = GUICtrlCreateCheckbox("Install Aircard Connection Entries", 16, 96, 185, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$FormsCheckbox = GUICtrlCreateCheckbox("Install Recruiter Forms", 16, 120, 185, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$ScandallCheckbox = GUICtrlCreateCheckbox("Install Scandall21 Program", 16, 144, 185, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$SnapshotCheckbox = GUICtrlCreateCheckbox("Install Snapshot Viewer", 16, 168, 185, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$PrinterCheckbox = GUICtrlCreateCheckbox("Install Lexmark Printer Drivers", 16, 216, 185, 17)
GUICtrlSetState(-1, $GUI_DISABLE)
$InstallButton = GUICtrlCreateButton("I&nstall", 24, 296, 75, 25, 0)
GUICtrlSetOnEvent(-1, "InstallButtonclick")
$ExitButton = GUICtrlCreateButton("E&xit", 120, 296, 75, 25, 0)
GUICtrlSetOnEvent(-1, "ExitButtonclick")
$Pic1 = GUICtrlCreatePic("C:\Photos\arng-pa-3.gif", 120, 8, 81, 73, BitOR($SS_NOTIFY,$WS_GROUP))
$RoadmapCheckbox = GUICtrlCreateCheckbox("Install Roadmap for Success ", 16, 192, 185, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$RunCheckbox = GUICtrlCreateCheckbox("Run Additional Program...", 16, 240, 185, 17)
GUICtrlSetOnEvent(-1, "RunCheckboxClick")
$RunInput = GUICtrlCreateInput("", 32, 264, 129, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
$BrowseButton = GUICtrlCreateButton("Browse...", 168, 264, 57, 17, 0)
GUICtrlSetOnEvent(-1, "BrowseButtonclick")
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
        

While 1
    Sleep(100)
WEnd


Func BrowseButtonclick()
    $file = FileOpenDialog("Select Source File", @WindowsDir, "All (*.*)", 1 + 2)
    GUICtrlSetData($RunInput, $file)
EndFunc

        
Func CUBRadioClick()
    GUICtrlSetState($PrinterCheckbox, $GUI_DISABLE)
    GUICtrlSetState($PrinterCheckbox, $GUI_UNCHECKED)
EndFunc

        
Func ExitButtonclick()
    Exit
EndFunc

        
Func InstallButtonclick()
    $cub = BitAnd(GUICtrlGetState($CUBRadio), $GUI_CHECKED)<>0
    $rws = BitAnd(GUICtrlGetState($RWSRadio), $GUI_CHECKED)<>0
    Select
        Case $cub = $GUI_CHECKED
            RunAsSet("user", @ComputerName, "password")
        Case $rws = $GUI_CHECKED
            RunAsSet("user2", @ComputerName, "password2")
    EndSelect
        
        AircardInstall()
        FormsInstall()
        ScandallInstall()
        SnapshotInstall()
        RoadmapInstall()
        PrinterInstall()
        ScannerInstall()
        Sleep(3000)
        RunAsSet()
        Exit
EndFunc

        
Func LoadFormClose()
    Exit
EndFunc

        
Func RunCheckboxClick()
    $run = BitAND(GUICtrlRead($RunCheckbox), $GUI_CHECKED)
    If $run = $GUI_CHECKED Then
        GUICtrlSetState($RunInput, $GUI_ENABLE)
        GUICtrlSetState($BrowseButton, $GUI_ENABLE)
    Else
        GUICtrlSetState($RunInput, $GUI_DISABLE)
        GUICtrlSetState($BrowseButton, $GUI_DISABLE)
    EndIf
EndFunc

        
Func RWSRadioClick()
    GUICtrlSetState($PrinterCheckbox, $GUI_ENABLE)
    GUICtrlSetState($PrinterCheckbox, $GUI_CHECKED)
EndFunc


Func AircardInstall()
    $air = BitAnd(GUICtrlGetState($AircardCheckbox), $GUI_CHECKED)
    If  $air = $GUI_CHECKED Then
        FileInstall("ANG  TIER II  SPRINT AIRCARD-E.pcf", "C:\Program Files\Cisco\RSVPN Client\Profiles\ANG  TIER II  SPRINT AIRCARD-E.pcf", 1)
        FileInstall("ANG  TIER I  SPRINT AIRCARD-E.pcf", "C:\Program Files\Cisco\RSVPN Client\Profiles\ANG  TIER I  SPRINT AIRCARD-E.pcf", 1)
        Sleep(3000)
    EndIf
EndFunc


Func FormsInstall()
    $forms = BitAnd(GUICtrlGetState($FormsCheckbox), $GUI_CHECKED)
    If  $forms = $GUI_CHECKED Then
        If BitAnd(GUICtrlGetState($CUBRadio), $GUI_CHECKED) Then
            RunWait("FormsCUB.exe")
        Else
            RunWait("FormsRWS.exe")
        EndIf
        Sleep(3000)
    EndIf
EndFunc


Func ScandallInstall()
    $scan = BitAnd(GUICtrlGetState($ScandallCheckbox), $GUI_CHECKED)
    If  $scan = $GUI_CHECKED Then
        Run("Scandall21.exe")
        Do
            Sleep(1000)
        Until WinExists("Attention", "This machine has been identified")
        ControlClick("Attention", "This machine has been identified", 2)
        Sleep(3000)
    EndIf
EndFunc


Func SnapshotInstall()
    $snap = BitAnd(GUICtrlGetState($SnapshotCheckbox), $GUI_CHECKED)
    If  $snap = $GUI_CHECKED Then
        Run("snpvw.exe")
        Do
            Sleep(1000)
        Until WinExists("Snapshot", "Would you like to install")
        ControlClick("Snapshot", "Would you like to install", 6)
        Do
            Sleep(1000)
        Until WinExists("Snapshot", "following license agreement.")
        ControlClick("Snapshot", "following license agreement.", 6)
        Do
            Sleep(1000)
        Until WinExists("Snapshot", "Welcome to the Snapshot")
        ControlClick("Snapshot", "Welcome to the Snapshot", 8)
        Do 
            Sleep(1000)
        Until WinExists("Snapshot", "following destination folder")
        ControlClick("Snapshot", "following destination folder", 1)
        Do
            Sleep(1000)
        Until WinExists("Snapshot", "click the large button")
        ControlClick("Snapshot", "click the large button", 14)
        Do
            Sleep(1000)
        Until WinExists("Snapshot", "was completed successfully.")
        ControlClick("Snapshot", "was completed successfully.", 1)
        Sleep(3000)
    EndIf
EndFunc


Func RoadmapInstall()
    $road = BitAnd(GUICtrlGetState($RoadmapCheckbox), $GUI_CHECKED)
    If  $road = $GUI_CHECKED Then
        Run("arng_rmfs.exe")
        Do
            Sleep(1000)
        Until WinExists("Roadmap", "wizard will guide you")
        ControlClick("Roadmap", "wizard will guide you", 1)
        Do
            Sleep(1000)
        Until WinExists("Roadmap", "Please review the license")
        ControlClick("Roadmap", "Please review the license", 1)
        Do
            Sleep(1000)
        Until WinExists("Roadmap", "Choose which features")
        ControlClick("Roadmap", "Choose which features", 1)
        Do
            Sleep(1000)
        Until WinExists("Roadmap", "Choose the folder")
        If BitAnd(GUICtrlGetState($CUBRadio), $GUI_CHECKED) Then
            ControlSetText("Roadmap", "Choose the folder", 1019, "C:\Roadmap For Success")
            ControlClick("Roadmap", "Choose the folder", 1)
        Else
            ControlClick("Roadmap", "Choose the folder", 1)
        EndIf
        Do
            Sleep(1000)
        Until WinExists("Roadmap", "has been installed")
        ControlClick("Roadmap", "has been installed", 1203)
        ControlClick("Roadmap", "has been installed", 1)
        Sleep(3000)
    EndIf
EndFunc

Func PrinterInstall()
    $print = BitAnd(GUICtrlGetState($PrinterCheckbox), $GUI_CHECKED)
    If  $print = $GUI_CHECKED Then
        Run("LexmarkX215.exe")
        Do
            Sleep(1000)
        Until WinExists("X215 Windows", "will help install X215")
        ControlClick("X215 Windows", "will help install X215", 12324)
        Do
            Sleep(1000)
        Until WinExists("X215 Windows", "enter the folder where")
        ControlClick("X215 Windows", "enter the folder where", 12324)
        Do 
            Sleep(1000)
        Until WinExists("Add Printer", "wizard helps you install")
        ControlClick("Add Printer", "wizard helps you install", 12324)
        Do
            Sleep(1000)
        Until WinExists("Add Printer", "Select the option")
        ControlClick("Add Printer", "Select the option", 4665)
        ControlClick("Add Printer", "Select the option", 12324)
        Do 
            Sleep(1000)
        Until WinExists("Add Printer", "Select the port")
        ControlClick("Add Printer", "Select the port", 12324)
        Do
            Sleep(1000)
        Until WinExists("Add printer", "Select the manufacturer")
        ControlClick("Add printer", "Select the manufacturer", 1567)
        Do
            Sleep(1000)
        Until WinExists("Install From", "installation disk")
        ControlSetText("Install From", "installation disk", 1001, "C:\lexmark\Driver\English\Print\AddPrint\WinXP")
        ControlClick("Install From", "installation disk", 1)
        Do
            Sleep(1000)
        Until WinExists("Add Printer", "model of your printer")
        ControlClick("Add Printer", "model of your printer", 12324)
        Do 
            Sleep(1000)
        Until WinExists("Add Printer", "name for this printer")
        ControlClick("Add Printer", "name for this printer", 3520)
        ControlClick("Add Printer", "name for this printer", 12324)
        Do
            Sleep(1000)
        Until WinExists("Add Printer", "want to share")
        ControlClick(("Add Printer", "want to share", 12324)
        Do 
            Sleep(1000)
        Until WinExists("Add Printer", "print a test page")
        ControlClick("Add Printer", "print a test page", 3521)
        ControlClick("Add Printer", "print a test page", 12324)
        Do
            Sleep(1000)
        Until WinExists("Add Printer", "successfully completed")
        ControlClick("Add Printer", "successfully completed", 12325)
        Sleep(3000)
    EndIf
EndFunc


Func ScannerInstall()
    $scan = BitAnd(GUICtrlGetState($PrinterCheckbox), $GUI_CHECKED)
    If  $scan = $GUI_CHECKED Then
        Run("LexmarkX215Scan.exe")
        Do
            Sleep(1000)
        Until WinExists("X215 Windows", "will help install X215")
        ControlClick("X215 Windows", "will help install X215", 12324)
        Do 
            Sleep(1000)
        Until WinExists("X215 Windows", "enter the folder")
        ControlClick("X215 Windows", "enter the folder", 12324)
        Do
            Sleep(1000)
        Until WinExists("InstallShield", "will install Lexmark X215")
        ControlClick("InstallShield", "will install Lexmark X215", 1)
        Do
            Sleep(1000)
        Until WinExists("InstallShield", "restart your computer")
        ControlClick("InstallShield", "restart your computer", 1)
        Sleep(3000)
    EndIf
EndFunc
Link to comment
Share on other sites

OK See what you can find wrong with this. I know it's not elegant, but I just need it to work. Thanks for the help!

I am surprised to find that you don't get $GUI_CHECKED as part of GuiCtrlGetState(). Changed them all to GuiCtrlRead() and it works. The following version is modified to not make any changes to the local environment, as a demo:

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)
Opt("WinTitleMatchMode", 2)
Opt("TrayIconDebug", 1)

$LoadForm = GUICreate("New Machine Load Utility", 228, 333, 383, 180)
GUISetOnEvent($GUI_EVENT_CLOSE, "LoadFormClose")
$PlatformGroup = GUICtrlCreateGroup("Platform", 8, 8, 73, 73)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$CUBRadio = GUICtrlCreateRadio("CUB", 16, 32, 49, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetOnEvent(-1, "CUBRadioClick")
$RWSRadio = GUICtrlCreateRadio("RWS", 16, 56, 49, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetOnEvent(-1, "RWSRadioClick")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$AircardCheckbox = GUICtrlCreateCheckbox("Install Aircard Connection Entries", 16, 96, 185, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$FormsCheckbox = GUICtrlCreateCheckbox("Install Recruiter Forms", 16, 120, 185, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$ScandallCheckbox = GUICtrlCreateCheckbox("Install Scandall21 Program", 16, 144, 185, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$SnapshotCheckbox = GUICtrlCreateCheckbox("Install Snapshot Viewer", 16, 168, 185, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$PrinterCheckbox = GUICtrlCreateCheckbox("Install Lexmark Printer Drivers", 16, 216, 185, 17)
GUICtrlSetState(-1, $GUI_DISABLE)
$InstallButton = GUICtrlCreateButton("I&nstall", 24, 296, 75, 25, 0)
GUICtrlSetOnEvent(-1, "InstallButtonclick")
$ExitButton = GUICtrlCreateButton("E&xit", 120, 296, 75, 25, 0)
GUICtrlSetOnEvent(-1, "ExitButtonclick")
$Pic1 = GUICtrlCreatePic("C:\Photos\arng-pa-3.gif", 120, 8, 81, 73, BitOR($SS_NOTIFY, $WS_GROUP))
$RoadmapCheckbox = GUICtrlCreateCheckbox("Install Roadmap for Success ", 16, 192, 185, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$RunCheckbox = GUICtrlCreateCheckbox("Run Additional Program...", 16, 240, 185, 17)
GUICtrlSetOnEvent(-1, "RunCheckboxClick")
$RunInput = GUICtrlCreateInput("", 32, 264, 129, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
$BrowseButton = GUICtrlCreateButton("Browse...", 168, 264, 57, 17, 0)
GUICtrlSetOnEvent(-1, "BrowseButtonclick")
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd



Func BrowseButtonclick()
    $file = FileOpenDialog("Select Source File", @WindowsDir, "All (*.*)", 1 + 2)
    GUICtrlSetData($RunInput, $file)
EndFunc   ;==>BrowseButtonclick


Func CUBRadioClick()
    GUICtrlSetState($PrinterCheckbox, $GUI_DISABLE)
    GUICtrlSetState($PrinterCheckbox, $GUI_UNCHECKED)
EndFunc   ;==>CUBRadioClick


Func ExitButtonclick()
    Exit
EndFunc   ;==>ExitButtonclick


Func InstallButtonclick()
    $cub = BitAND(GUICtrlRead($CUBRadio), $GUI_CHECKED)
    $rws = BitAND(GUICtrlRead($RWSRadio), $GUI_CHECKED)

    Select
        Case $cub = $GUI_CHECKED
            MsgBox(64, "Debug", "password executing...")
        Case $rws = $GUI_CHECKED
            MsgBox(64, "Debug", "password2 executing...")
    EndSelect

    AircardInstall()
    FormsInstall()
    ScandallInstall()
    SnapshotInstall()
    RoadmapInstall()
    PrinterInstall()
    ScannerInstall()
    Sleep(3000)
    RunAsSet()
    Exit
EndFunc   ;==>InstallButtonclick

Func LoadFormClose()
    Exit
EndFunc   ;==>LoadFormClose

Func RunCheckboxClick()
    $run = BitAND(GUICtrlRead($RunCheckbox), $GUI_CHECKED)
    If $run = $GUI_CHECKED Then
        GUICtrlSetState($RunInput, $GUI_ENABLE)
        GUICtrlSetState($BrowseButton, $GUI_ENABLE)
    Else
        GUICtrlSetState($RunInput, $GUI_DISABLE)
        GUICtrlSetState($BrowseButton, $GUI_DISABLE)
    EndIf
EndFunc   ;==>RunCheckboxClick

Func RWSRadioClick()
    GUICtrlSetState($PrinterCheckbox, $GUI_ENABLE)
    GUICtrlSetState($PrinterCheckbox, $GUI_CHECKED)
EndFunc   ;==>RWSRadioClick

Func AircardInstall()
    $air = BitAND(GUICtrlRead($AircardCheckbox), $GUI_CHECKED)
    If $air = $GUI_CHECKED Then
        MsgBox(64, "Debug", "AircardInstall executing...")
    EndIf
EndFunc   ;==>AircardInstall

Func FormsInstall()
    $forms = BitAND(GUICtrlRead($FormsCheckbox), $GUI_CHECKED)
    If $forms = $GUI_CHECKED Then
        If BitAND(GUICtrlRead($CUBRadio), $GUI_CHECKED) Then
            MsgBox(64, "Debug", "FormsCUB.exe executing...")
        Else
            MsgBox(64, "Debug", "FormsRWS.exe executing...")
        EndIf
    EndIf
EndFunc   ;==>FormsInstall

Func ScandallInstall()
    $scan = BitAND(GUICtrlRead($ScandallCheckbox), $GUI_CHECKED)
    If $scan = $GUI_CHECKED Then
        MsgBox(64, "Debug", "ScandallInstall executing...")
    EndIf
EndFunc   ;==>ScandallInstall

Func SnapshotInstall()
    $snap = BitAND(GUICtrlRead($SnapshotCheckbox), $GUI_CHECKED)
    If $snap = $GUI_CHECKED Then
        MsgBox(64, "Debug", "SnapshotInstall executing...")
    EndIf
EndFunc   ;==>SnapshotInstall

Func RoadmapInstall()
    $road = BitAND(GUICtrlRead($RoadmapCheckbox), $GUI_CHECKED)
    If $road = $GUI_CHECKED Then
        MsgBox(64, "Debug", "RoadmapInstall executing...")
    EndIf
EndFunc   ;==>RoadmapInstall

Func PrinterInstall()
    $print = BitAND(GUICtrlRead($PrinterCheckbox), $GUI_CHECKED)
    If $print = $GUI_CHECKED Then
        MsgBox(64, "Debug", "PrinterInstall executing...")
    EndIf
EndFunc   ;==>PrinterInstall

Func ScannerInstall()
    $scan = BitAND(GUICtrlRead($PrinterCheckbox), $GUI_CHECKED)
    If $scan = $GUI_CHECKED Then
        MsgBox(64, "Debug", "ScannerInstall executing...")
    EndIf
EndFunc   ;==>ScannerInstall

I'm not totally sure this is the intended behavior of GuiCtrlGetState() and will ask in the Bugs forum. At any rate, GuiCtrlRead() fixes it.

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...