Jump to content

Clicking on button in GUICtrlInput not doing anything


Recommended Posts

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!

#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

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  ;)

#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

 

Link to comment
Share on other sites

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

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  :)

#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

 

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...