JustinM Posted September 1, 2016 Share Posted September 1, 2016 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 Link to comment Share on other sites More sharing options...
JohnOne Posted September 1, 2016 Share Posted September 1, 2016 If ProcessExists(4496) Then ;blah Else ;blah EndIf AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
JustinM Posted September 1, 2016 Author Share Posted September 1, 2016 Where should I insert that into the script? Should I do it like this: Case $Yes StartBatch() Case $No Exit EndSwitch Link to comment Share on other sites More sharing options...
JustinM Posted September 1, 2016 Author Share Posted September 1, 2016 Case $Yes StartBatch() If ProcessExists(4496) Then ;blah Else ;blah EndIf Case $No Exit Link to comment Share on other sites More sharing options...
JohnOne Posted September 1, 2016 Share Posted September 1, 2016 Case $Yes ;whayever Case $No If ProcessExists(4496) Then ;give an error Else StartBatch() EndIf Exit AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
BrewManNH Posted September 1, 2016 Share Posted September 1, 2016 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 GudeHow 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 Link to comment Share on other sites More sharing options...
JustinM Posted September 1, 2016 Author Share Posted September 1, 2016 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? expandcollapse 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 Link to comment Share on other sites More sharing options...
JustinM Posted September 1, 2016 Author Share Posted September 1, 2016 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 expandcollapse 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 Link to comment Share on other sites More sharing options...
argumentum Posted September 2, 2016 Share Posted September 2, 2016 If RegRead("HKLM64\software\microsoft\windows\currentversion\setup\state\", "IMAGE_STATE_SPECIALIZE_RESEAL_TO_AUDIT") = "what" Then Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Developers Jos Posted September 2, 2016 Developers Share Posted September 2, 2016 (edited) Please refrain from posting your question twice and stick to this single thread. Jos *Merged* Edited September 2, 2016 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
JustinM Posted September 2, 2016 Author Share Posted September 2, 2016 @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 expandcollapse 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 $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 Link to comment Share on other sites More sharing options...
argumentum Posted September 2, 2016 Share Posted September 2, 2016 (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 September 2, 2016 by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
JustinM Posted September 2, 2016 Author Share Posted September 2, 2016 @argumentum You Rock, thank you! argumentum 1 Link to comment Share on other sites More sharing options...
JustinM Posted September 2, 2016 Author Share Posted September 2, 2016 @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. expandcollapse 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 $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 Link to comment Share on other sites More sharing options...
spudw2k Posted September 2, 2016 Share Posted September 2, 2016 (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 September 2, 2016 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
Developers Jos Posted September 2, 2016 Developers Share Posted September 2, 2016 That needs an extra space before the /c. argumentum 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
spudw2k Posted September 2, 2016 Share Posted September 2, 2016 Whoops, you're right....corrected. Thanks Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
argumentum Posted September 2, 2016 Share Posted September 2, 2016 (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 optionRun(@ComSpec & ' /c "c:\users\'&@UserName&'\Desktop\Batch\Install.bat"',@ScriptDir) is another, etc. Edited September 2, 2016 by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
JustinM Posted September 2, 2016 Author Share Posted September 2, 2016 All of you are awesome! It's finally working! Thanks all! argumentum 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now