TheCrimsonCrusader Posted September 14, 2020 Share Posted September 14, 2020 Greetings, In the code below, I just have a GUI and within that GUI, I have a button called "Unlock BitLocker" which in turn, calls a function that has an input field. When I click on the OK button for the input field dialog box, the button doesn't do anything. I'm sure it's something simple, but apparently not simple enough for me. 🙂 Any help would be greatly appreciated! Thanks! expandcollapse popup#include <GuiConstants.au3> Opt("GUIOnEventMode", 1) $GUI = GUICreate("Test GUI",400,100,-1,-1,BitOR($WS_POPUP, $WS_DLGFRAME, $WS_EX_TOPMOST), 0) WinSetOnTop ($GUI, "",1) $UNLOCK_BITLOCKER = GUICtrlCreateButton("Unlock BitLocker", 20, 20, 200, 25) GUICtrlSetOnEvent($UNLOCK_BITLOCKER,"UNLOCK_BITLOCKER_FUNCTION") GUISetState() While 1 Sleep(1000) WEnd Func UNLOCK_BITLOCKER_FUNCTION() GUICreate("Microsoft BitLocker",720, 165, -1,-1,BitOR($WS_DLGFRAME, $WS_EX_TOPMOST), 0) WinSetOnTop ("Microsoft BitLocker", "",1) GUICtrlCreateLabel("Please enter the BitLocker recovery key and then click on the OK button:",10,10,700,35) GUICtrlSetFont (-1,-1, 800) $BitLockerRecoveryKey = GUICtrlCreateInput("", 10, 50, 700, 35) $idBtn = GUICtrlCreateButton("OK", 10, 100, 160, 35) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idBtn ExitLoop EndSwitch WEnd $BitLockerRecoveryKey2= GUICtrlRead($BitLockerRecoveryKey) $ReturnCode = RunWait("cmd.exe /c manage-bde -unlock c: -recoverypassword " & $BitLockerRecoveryKey2,"",@SW_HIDE) If $ReturnCode = "0" then MsgBox(262208,"Microsoft BitLocker","The BitLocker recovery volume is now unlocked.") GUIDelete("Microsoft BitLocker") Return Else MsgBox(262160,"Microsoft BitLocker","An invalid BitLocker recovery key was specified. Please try again.") GUIDelete("Microsoft BitLocker") Return EndIf EndFunc Link to comment Share on other sites More sharing options...
Zedna Posted September 14, 2020 Share Posted September 14, 2020 (edited) Don't mix OnEvent and Message mode for your 2 GUIs. Edited September 14, 2020 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
TheCrimsonCrusader Posted September 17, 2020 Author Share Posted September 17, 2020 Sorry, it's a bit over my head. If I want to use the OnEvent instead of the Message mode in the loop as a example, do I clear out everything in the loop outside of maybe having a sleep statement and another function call within the loop for the remaining part of the code? Link to comment Share on other sites More sharing options...
mikell Posted September 17, 2020 Share Posted September 17, 2020 Although mixing both modes is not recommended, It is possible by disabling/enabling OnEventMode before/after using MessageLoop mode But as said Zedna using only one is a much better practice expandcollapse popup#include <GuiConstants.au3> Opt("GUIOnEventMode", 1) $GUI = GUICreate("Test GUI",400,100,-1,-1,BitOR($WS_POPUP, $WS_DLGFRAME, $WS_EX_TOPMOST), 0) WinSetOnTop ($GUI, "",1) $UNLOCK_BITLOCKER = GUICtrlCreateButton("Unlock BitLocker", 20, 20, 200, 25) GUICtrlSetOnEvent($UNLOCK_BITLOCKER,"UNLOCK_BITLOCKER_FUNCTION") GUISetState() While 1 Sleep(1000) WEnd Func UNLOCK_BITLOCKER_FUNCTION() Opt("GUIOnEventMode", 0) GUICreate("Microsoft BitLocker",720, 165, -1,-1,BitOR($WS_DLGFRAME, $WS_EX_TOPMOST), 0) WinSetOnTop ("Microsoft BitLocker", "",1) GUICtrlCreateLabel("Please enter the BitLocker recovery key and then click on the OK button:",10,10,700,35) GUICtrlSetFont (-1,-1, 800) $BitLockerRecoveryKey = GUICtrlCreateInput("", 10, 50, 700, 35) $idBtn = GUICtrlCreateButton("OK", 10, 100, 160, 35) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idBtn ExitLoop EndSwitch WEnd $BitLockerRecoveryKey2= GUICtrlRead($BitLockerRecoveryKey) $ReturnCode = RunWait("cmd.exe /c manage-bde -unlock c: -recoverypassword " & $BitLockerRecoveryKey2,"",@SW_HIDE) If $ReturnCode = "0" then MsgBox(262208,"Microsoft BitLocker","The BitLocker recovery volume is now unlocked.") Else MsgBox(262160,"Microsoft BitLocker","An invalid BitLocker recovery key was specified. Please try again.") EndIf GUIDelete("Microsoft BitLocker") Return Opt("GUIOnEventMode", 1) EndFunc TheCrimsonCrusader 1 Link to comment Share on other sites More sharing options...
TheCrimsonCrusader Posted September 17, 2020 Author Share Posted September 17, 2020 Thanks for that, mikell. That works but I agree that using one mode would be preferred. I would prefer to use the OnEvent only if possible, but I I add an OnEvent under the $idBtn = GUICtrlCreateButton("OK", 10, 100, 160, 35) line and try to call that as an additional function instead of in the loop, it does nothing. Link to comment Share on other sites More sharing options...
mikell Posted September 17, 2020 Share Posted September 17, 2020 There are several ways to do that. The easiest one is to create the 2 gui and show/hide them on demand, this makes it simple to assign a function to a control as needed by the event mode Example below - but please remember that the help file and the wiki are your best friends expandcollapse popup#include <GuiConstants.au3> Opt("GUIOnEventMode", 1) $GUI = GUICreate("Test GUI",400,100,-1,-1,BitOR($WS_POPUP, $WS_DLGFRAME, $WS_EX_TOPMOST), 0) WinSetOnTop ($GUI, "",1) $UNLOCK_BITLOCKER = GUICtrlCreateButton("Unlock BitLocker", 20, 20, 200, 25) GUICtrlSetOnEvent($UNLOCK_BITLOCKER,"UNLOCK_BITLOCKER_FUNCTION") GUISetState(@SW_SHOW) $test = GUICreate("Microsoft BitLocker",720, 165, -1,-1,BitOR($WS_DLGFRAME, $WS_EX_TOPMOST), 0) WinSetOnTop ("Microsoft BitLocker", "",1) GUICtrlCreateLabel("Please enter the BitLocker recovery key and then click on the OK button:",10,10,700,35) GUICtrlSetFont (-1,-1, 800) $BitLockerRecoveryKey = GUICtrlCreateInput("", 10, 50, 700, 35) $idBtn = GUICtrlCreateButton("OK", 10, 100, 160, 35) GUICtrlSetOnEvent($idBtn,"_testkey") GUISetState(@SW_HIDE) While 1 Sleep(1000) WEnd Func UNLOCK_BITLOCKER_FUNCTION() GUISetState(@SW_SHOW, $test) EndFunc Func _testkey() $BitLockerRecoveryKey2= GUICtrlRead($BitLockerRecoveryKey) $ReturnCode = RunWait("cmd.exe /c manage-bde -unlock c: -recoverypassword " & $BitLockerRecoveryKey2,"",@SW_HIDE) If $ReturnCode = "0" then MsgBox(262208,"Microsoft BitLocker","The BitLocker recovery volume is now unlocked.") GUIDelete("Microsoft BitLocker") Else MsgBox(262160,"Microsoft BitLocker","An invalid BitLocker recovery key was specified. Please try again.") GUISetState(@SW_HIDE, $test) EndIf EndFunc TheCrimsonCrusader 1 Link to comment Share on other sites More sharing options...
Zedna Posted September 17, 2020 Share Posted September 17, 2020 Definitely look here https://www.autoitscript.com/wiki/Managing_Multiple_GUIs Resources UDF ResourcesEx UDF AutoIt Forum Search 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