Tn60 Posted May 30, 2020 Posted May 30, 2020 Hi I am writing a small shut down program. I have a problem with getting shutdown.exe /s /t 100 working. If I am running from a dos windows it is working fine. The problem starts when i give it a parameter thru autoit. I appreciate any and all help. Thanks #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 177, 106, 192, 124) $Input1 = GUICtrlCreateInput("", 32, 16, 105, 21) $Button1 = GUICtrlCreateButton("Button1", 32, 48, 105, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 If $Input1="" Then MsgBox(0,0,'No number') Else $Input1=GUICtrlRead($Input1) $Input1=Number($Input1) MsgBox(0,0,IsNumber($Input1)) $some_n='@ComSpec & " /c c:\windows\system32\shutdown.exe /s /t ' & $Input1 & '"' MsgBox(0,0,$some_n) Run($some_n) EndIf EndSwitch WEnd
Musashi Posted May 30, 2020 Posted May 30, 2020 33 minutes ago, Tn60 said: $some_n='@ComSpec & " /c c:\windows\system32\shutdown.exe /s /t ' & $Input1 & '"' Try : Run("c:\windows\system32\shutdown.exe /s /t 60", "", @SW_HIDE) or :Run(@ComSpec & " /c shutdown /s /t 60", "", @SW_HIDE) "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
Tn60 Posted May 30, 2020 Author Posted May 30, 2020 Thanks for your reply. What you gave me is working and it worked before. In my program, however, I would like to use different time amounts, this is why I am using the input field. When putting the time from the input field to the dos script that is where I am having problems. Maybe my description wasn't clear enough. Thanks
Musashi Posted May 30, 2020 Posted May 30, 2020 (edited) #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #Region ### START Koda GUI section ### Form= Local $nMsg, $iInputNum = 0, $sShutdownCommand Local $Form1 = GUICreate("Form1", 177, 106, 192, 124) Local $idInput1 = GUICtrlCreateInput("", 32, 16, 105, 21) Local $idButton1 = GUICtrlCreateButton("Button1", 32, 48, 105, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idButton1 If StringRegExp(GUICtrlRead($idInput1), "^(\d+)$") Then $iInputNum = Number(GUICtrlRead($idInput1)) $sShutdownCommand = @SystemDir & "\shutdown.exe /s /t " & $iInputNum If MsgBox($MB_OKCANCEL, "", $sShutdownCommand & @CRLF) = $IDOK Then Run($sShutdownCommand) Else GUICtrlSetData($idInput1, "") EndIf Else MsgBox(0, "", 'Input empty or not a valid number') GUICtrlSetData($idInput1, "") EndIf EndSwitch WEnd @Tn60 : I added a regular expression so that you can also use 0 as a numeric value. Edited May 30, 2020 by Musashi Insert MsgBox with MB_OKCANCEL, add a RegEx "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
Tn60 Posted May 30, 2020 Author Posted May 30, 2020 Hi Thanks for your reply. This is what I wanted. I appreciate your help. Thanks
Musashi Posted May 30, 2020 Posted May 30, 2020 2 minutes ago, Tn60 said: Thanks for your reply. This is what I wanted. I appreciate your help. You are welcome . Check the latest version, because I added a regular expression. "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
Musashi Posted May 30, 2020 Posted May 30, 2020 5 minutes ago, Tn60 said: I will. I am curious about what did i do wrong. In your original script (posting #1) you used the result of : 2 hours ago, Tn60 said: $Input1 = GUICtrlCreateInput("", 32, 16, 105, 21) for some further processing. However, GUICtrlCreateInput returns the ID of the control, not the value. It can increase readability by giving variables a prefix, e.g. $aArr for array or $idInput for ID's etc. "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
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