JustinM

Help with IF/THEN for GUI

19 posts in this topic

I have my Yes and No GUI setup -- when they click yes it will run a batch file, if they click no, the GUI will exit.

 

My question is, when they click yes, I need an if/then statement to see: if PID 4496 is running give an error, if PID 4496 is not running, continue with the batch file.

 

Can someone help me? Below is a copy of the script

 

RequireAdmin

Region ;**** Directives created by AutoIt3Wrapper_GUI ****

AutoIt3Wrapper_Icon=..\icon.ico

AutoIt3Wrapper_UseUpx=y

AutoIt3Wrapper_Run_Au3Stripper=y

EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

include <ButtonConstants.au3>

include <GUIConstantsEx.au3>

include <StaticConstants.au3>

include <WindowsConstants.au3>

Region ### START Koda GUI section ### Form= Global $Batch = GUICreate("Sentinel", 209, 69, 388, 216) Global $Yes = GUICtrlCreateButton("Yes", 16, 32, 75, 25) Global $No = GUICtrlCreateButton("No", 112, 32, 75, 25) Global $Is_The_System_Already_Sysprepped = GUICtrlCreateLabel("Is The System Already Sysprepped ?", 16, 8, 180, 17) GUISetState(@SW_SHOW)

EndRegion ### END Koda GUI section

While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit

    Case $Yes
        StartBatch()

    Case $No
        Exit

EndSwitch

WEnd

Func StartBatch() Run('install.bat')

;WinWaitActive('C:\Windows\system32\cmd.exe') EndFunc

;PID 4496

Share this post


Link to post
Share on other sites



Where should I insert that into the script?

Should I do it like this: 

Case $Yes

StartBatch() Case $No Exit EndSwitch

 

Share this post


Link to post
Share on other sites

Please use code tags when you post code, use the "<>" button in the editor. Your original post is a hot mess with the run on lines and very hard to follow.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I want to change the script up and instead of reading a process ID, it needs to read a registry, but it is not working :/

Can you help me please?

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\icon.ico
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_Run_Au3Stripper=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Global $Sentinel = GUICreate("Batch", 209, 69, 388, 216)
Global $Yes = GUICtrlCreateButton("Yes", 16, 32, 75, 25)
Global $No = GUICtrlCreateButton("No", 112, 32, 75, 25)
Global $Is_The_System_Already_Sysprepped = GUICtrlCreateLabel("Click Yes to Install Batch", 16, 8, 180, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Yes
            If RegRead("HKLM64\software\microsoft\windows\currentversion\setup\state\", "IMAGE_STATE_SPECIALIZE_RESEAL_TO_AUDIT") Then
                MsgBox (16, "Please SysPrep System To Run", "Please SysPrep System To Install Batch")
            Else
                StartBatch()
                Exit

            EndIf

        Case $No
            Exit

    EndSwitch
WEnd

Func StartBatch()
    Run('install.bat')
    ;WinWaitActive('C:\Windows\system32\cmd.exe')
EndFunc

 

Share this post


Link to post
Share on other sites

I want to change the script up and instead of reading a process ID, it needs to read a registry, but it is not working :/

Can you help me please?

collapse popup
#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\icon.ico
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_Run_Au3Stripper=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Global $Sentinel = GUICreate("Batch", 209, 69, 388, 216)
Global $Yes = GUICtrlCreateButton("Yes", 16, 32, 75, 25)
Global $No = GUICtrlCreateButton("No", 112, 32, 75, 25)
Global $Is_The_System_Already_Sysprepped = GUICtrlCreateLabel("Click Yes to Install Batch", 16, 8, 180, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Yes
            If RegRead("HKLM64\software\microsoft\windows\currentversion\setup\state\", "IMAGE_STATE_SPECIALIZE_RESEAL_TO_AUDIT") Then
                MsgBox (16, "Please SysPrep System To Run", "Please SysPrep System To Install Batch")
            Else
                StartBatch()
                Exit

            EndIf

        Case $No
            Exit

    EndSwitch
WEnd

Func StartBatch()
    Run('install.bat')
    ;WinWaitActive('C:\Windows\system32\cmd.exe')
EndFunc

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Please refrain from posting your question twice and stick to this single thread.

Jos

*Merged*

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

@argumentum 

Can you please help me out a little more? It's still not working properly. Below is an image of the actual registry and code

 

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\icon.ico
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_Run_Au3Stripper=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Global $Batch = GUICreate("Sentinel", 209, 69, 388, 216)
Global $Yes = GUICtrlCreateButton("Yes", 16, 32, 75, 25)
Global $No = GUICtrlCreateButton("No", 112, 32, 75, 25)
Global $Is_The_System_Already_Sysprepped = GUICtrlCreateLabel("Click Yes to Install Batch", 16, 8, 180, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Yes
            If RegRead("HKLM\software\microsoft\windows\currentversion\setup\state\", "IMAGE_STATE_SPECIALIZE_RESEAL_TO_AUDIT") = "IMAGE_STATE_SPECIALIZE_RESEAL_TO_AUDIT" Then
                MsgBox (16, "Please SysPrep System To Run", "Please SysPrep System To Install Sentinel")
            Else
                StartBatch()
                Exit

            EndIf

        Case $No
            Exit

    EndSwitch
WEnd

Func StartBatch()
    Run('install.bat')
    ;WinWaitActive('C:\Windows\system32\cmd.exe')
EndFunc

 

 

regedit.PNG

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

ok @JustinM. The help file say:  RegRead ( "keyname", "valuename" ) , so, it should be
 RegRead("HKLM\software\microsoft\windows\currentversion\setup\state", "ImageState") = "IMAGE_STATE_SPECIALIZE_RESEAL_TO_AUDIT" Then

That's all :) 
 

Edited by argumentum

Share this post


Link to post
Share on other sites

@argumentum

I am now having an issue running the batch.bat from a different folder and I don't know why. I am pointing to the correct folder. Is seems like %username% is breaking it. What is a simple fix for this? The usernames are different every time. I appreciate your help.

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=icon.ico
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_Run_Au3Stripper=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Global $Batch = GUICreate("Sentinel", 337, 111, 192, 124)
GUISetFont(8, 800, 0, "MagistralC-Bold")
Global $Yes = GUICtrlCreateButton("Yes", 8, 48, 147, 50)
Global $No = GUICtrlCreateButton("No", 184, 48, 147, 49)
Global $Proceed_To_Install_Sentinel = GUICtrlCreateLabel("Proceed To Install Batch?", 8, 8, 324, 31)
GUICtrlSetFont(-1, 18, 800, 0, "MagistralC-Bold")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Yes
            If RegRead("HKLM\software\microsoft\windows\currentversion\setup\state", "ImageState") = "IMAGE_STATE_SPECIALIZE_RESEAL_TO_AUDIT" Then
                MsgBox (16, "Please SysPrep System To Run", "Please SysPrep System To Install Batch")
            Else
                StartBatch()
                Exit

            EndIf

        Case $No
            Exit

    EndSwitch
WEnd

Func StartBatch()
    ;Run("install.bat")
    Run("c:\users\%username%\Desktop\Batch\Install.bat")

EndFunc

 

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

I suspect the %username% is being passed as a literal string.  You should be able to call comspec to have it translated into the environment variable.

Run(@ComSpec & " /c c:\users\%username%\Desktop\Batch\Install.bat")

alternatively you could use the UserProfileDir macro

Run(@UserProfileDir & "\Desktop\Batch\Install.bat")

 

Edited by spudw2k

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Run(@ComSpec & " /c c:\users\%username%\Desktop\Batch\Install.bat")
Run(@ComSpec & ' /c "c:\users\'&Env("username")&'\Desktop\Batch\Install.bat"','c:\users\'&Env("username") is one option
Run(@ComSpec & ' /c "c:\users\'&@UserName&'\Desktop\Batch\Install.bat"',@ScriptDir) is another, etc.

Edited by argumentum

Share this post


Link to post
Share on other sites

All of you are awesome! It's finally working! Thanks all!

1 person likes this

Share this post


Link to post
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