Jump to content

BlockInput() trouble


theholycow
 Share

Recommended Posts

I am trying to disable Ctrl-Alt-Del in a program. I do not know another way to do this except for blocking input if Ctrl or Alt or Delete is pressed. I want the only input allowed to be letters and numbers entered into a password form. I would imagine there is a simpler way, and if anyone has an idea I'd love to here it, but here's what I've come up with so far. The initial blocking works fine, too well actually. It will not unblock, so in testing I am forced to restart haha. Here's the code:

Method 1:

CODE

GuiCreate("ScreenLocker", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)

GuiSetState()

$input = GuiCtrlCreateInput("password", (@desktopwidth/2), (@desktopheight/2), 100, 20)

$inputbutton = GuiCtrlCreateButton("Enter", (@desktopwidth/2), ((@desktopheight/2) + 25), 80, 30)

While 1

$msg = GuiGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

Exit

Case $msg = $inputbutton ;reads the input box on button push

$pass = GuiCtrlRead($input)

If $pass = "password" Then ;allows access if the password is correct, i will change this to read an encrypted file later, for now this will do

GuictrlCreateLabel("correct!", 100, 100) ;just to verify until i get everything working

Sleep(1000)

Exit

EndIf

EndSelect

If _IsPressed("A2") Or _IsPressed("A3") Or _IsPressed("2E") Then

BlockInput(1)

Else

BlockInput(0)

EndIf

WEnd

Method 2:

CODE

GuiCreate("ScreenLocker", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)

GuiSetState()

$input = GuiCtrlCreateInput("password", (@desktopwidth/2), (@desktopheight/2), 100, 20)

$inputbutton = GuiCtrlCreateButton("Enter", (@desktopwidth/2), ((@desktopheight/2) + 25), 80, 30)

While 1

$msg = GuiGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

Exit

Case $msg = $inputbutton ;reads the input box on button push

$pass = GuiCtrlRead($input)

If $pass = "password" Then ;allows access if the password is correct

GuictrlCreateLabel("correct!", 100, 100)

Sleep(1000)

Exit

EndIf

EndSelect

If _IsPressed("A2") Or _IsPressed("A3") Or _IsPressed("2E") Then

BlockInput(1)

ElseIf Not _IsPressed("11") And Not _IsPressed("12") And Not _IsPressed("2E") Then

BlockInput(0)

EndIf

WEnd

Christianity: In the beginning, there was God, who always was there and created everything.Atheism: In the beginning, there was nothing, which exploded. Both sides look bad...

Link to comment
Share on other sites

I am trying to disable Ctrl-Alt-Del in a program. I do not know another way to do this except for blocking input if Ctrl or Alt or Delete is pressed. I want the only input allowed to be letters and numbers entered into a password form. I would imagine there is a simpler way, and if anyone has an idea I'd love to here it, but here's what I've come up with so far. The initial blocking works fine, too well actually. It will not unblock, so in testing I am forced to restart haha. Here's the code:

Method 1:

CODE

GuiCreate("ScreenLocker", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)

GuiSetState()

$input = GuiCtrlCreateInput("password", (@desktopwidth/2), (@desktopheight/2), 100, 20)

$inputbutton = GuiCtrlCreateButton("Enter", (@desktopwidth/2), ((@desktopheight/2) + 25), 80, 30)

While 1

$msg = GuiGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

Exit

Case $msg = $inputbutton ;reads the input box on button push

$pass = GuiCtrlRead($input)

If $pass = "password" Then ;allows access if the password is correct, i will change this to read an encrypted file later, for now this will do

GuictrlCreateLabel("correct!", 100, 100) ;just to verify until i get everything working

Sleep(1000)

Exit

EndIf

EndSelect

If _IsPressed("A2") Or _IsPressed("A3") Or _IsPressed("2E") Then

BlockInput(1)

Else

BlockInput(0)

EndIf

WEnd

Method 2:

CODE

GuiCreate("ScreenLocker", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)

GuiSetState()

$input = GuiCtrlCreateInput("password", (@desktopwidth/2), (@desktopheight/2), 100, 20)

$inputbutton = GuiCtrlCreateButton("Enter", (@desktopwidth/2), ((@desktopheight/2) + 25), 80, 30)

While 1

$msg = GuiGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

Exit

Case $msg = $inputbutton ;reads the input box on button push

$pass = GuiCtrlRead($input)

If $pass = "password" Then ;allows access if the password is correct

GuictrlCreateLabel("correct!", 100, 100)

Sleep(1000)

Exit

EndIf

EndSelect

If _IsPressed("A2") Or _IsPressed("A3") Or _IsPressed("2E") Then

BlockInput(1)

ElseIf Not _IsPressed("11") And Not _IsPressed("12") And Not _IsPressed("2E") Then

BlockInput(0)

EndIf

WEnd

This example might help. I found it easier to deal with the result of Ctrl Alt Del than to stop it.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

This example might help. I found it easier to deal with the result of Ctrl Alt Del than to stop it.

I tried doing it with the If WinExists then WinClose, problem is it still flashes the taskmanager and allows access to start menu, etc. I also want to block shortcuts like Alt F4. Alt Esc, stuff like that.

Christianity: In the beginning, there was God, who always was there and created everything.Atheism: In the beginning, there was nothing, which exploded. Both sides look bad...

Link to comment
Share on other sites

See here

...problem is it still flashes the taskmanager and allows access to start menu, etc. I also want to block shortcuts like Alt F4. Alt Esc, stuff like that.

Might want to read everything before you post, not being a jerk just pointing that out, but that will probably help him with TaskManager showing up.
Link to comment
Share on other sites

Might want to read everything before you post, not being a jerk just pointing that out, but that will probably help him with TaskManager showing up.

Well, I copied and ran the example that martin suggested, and had the taskmanager flashing problem. So now I looked at the one dbzfanatic suggested, and added the regwrite bit to disable it completely, but the start menu still flashes. I think I'll just disable that the same way I did the task manager, disable when the lock opens, and re enable when the password is right. Where's the key for that?

Edited by theholycow

Christianity: In the beginning, there was God, who always was there and created everything.Atheism: In the beginning, there was nothing, which exploded. Both sides look bad...

Link to comment
Share on other sites

Notice I didn't post the example, rasim did. I don't like taking credit for something someone else pointed out. What exactly are you making? A locking program?

Link to comment
Share on other sites

Notice I didn't post the example, rasim did. I don't like taking credit for something someone else pointed out. What exactly are you making? A locking program?

right, sorry rasim. And yeah, I've seen the other examples out there, I know there are working versions; but I'm trying to get better at this, not copy someone else's. The example rasim had up was almost exactly what I wanted, just some little stuff I added in to make it more mine, and this is the last thing I want to fix. Is there a Registry Key for disabling the Start Menu/Taskbar? I couldn't find one myself and Google didn't seem to have the answer either...

I also tried using something like this:

CODE
If WinExists("Task Manager", "Task Manager has been disabled by your administrator") Then

BlockInput(1)

Sleep(1000)

WinKill("Task Manager", "Task Manager has been disabled by your administrator")

Sleep(5000)

BlockInput(0)

Else

BlockInput(0)

EndIf

And many other variations of that

The If Winexists is the popup that occurs when you hit ctrl alt delete when taskmanager is disabled. The rest is obvious what I intended to do, but it doesnt seem to ever block input, and with a few practice runs I've been able to get past the lock with just the tiny flash of taskbar from the WinKill. Not sure how to fix this...

Christianity: In the beginning, there was God, who always was there and created everything.Atheism: In the beginning, there was nothing, which exploded. Both sides look bad...

Link to comment
Share on other sites

I had an idea. Why not try something like using _IsPressed() to check if ctrl,atl, or del is pressed and if it is block input until it's released?

Link to comment
Share on other sites

I had an idea. Why not try something like using _IsPressed() to check if ctrl,atl, or del is pressed and if it is block input until it's released?

I tried that originally, problem is once it blocks the input, it won't unblock, even if the key isnt presed anymore...

Christianity: In the beginning, there was God, who always was there and created everything.Atheism: In the beginning, there was nothing, which exploded. Both sides look bad...

Link to comment
Share on other sites

Well I have an idea of why that would happen. Try adding a TimerDiff() to your function with a reasonable time (1-2 minutes maybe) that it waits for the unpressed signal and manually unblocks when the time limit is reached. Also you could use a messagebox to tell the user the key isn't allowed. Like

MsgBox(64,"Error","That key is not allowed. Input blocked for %s minutes.")
where %s is the ammount of time. As another feature you could increment the time it's blocked with each keypress like.
If _IsPressed(*code for ctrl*) = 1 Then
$limit += 1
BlockInput(1)
MsgBox(64,"Error", "That key is not allowed. Input blocked for " & $limit & " minutes.")
$time = TimerInit()
If TimerDiff($time) >= ($limit * 60000) Then
BlockInput(0)
Endif
Endif
Hope these ideas help :). Sorry but I forgot the hex code for ctrl and I don't have time to look right now >.>;;. Edited by dbzfanatic
Link to comment
Share on other sites

Ugh. nothing seems to be working. It just wont unblock... Here's another way I tried it, just to see if anyone can find anything wrong with it...

CODE
;Select

; Case _IsPressed("11") = 1

; $ctrlpress = True

; Case _IsPressed("11") = 0

; $ctrlpress = False

;Case _IsPressed("12") = 1

; $altpress = True

;Case _IsPressed("12") = 0

; $altpress = False

;EndSelect

;If ($ctrlpress = True) Or ($altpress = True) Then

; BlockInput(1)

;ElseIf ($ctrlpress = False) And ($altpress = False) Then

; BlockInput(0)

;EndIf

Christianity: In the beginning, there was God, who always was there and created everything.Atheism: In the beginning, there was nothing, which exploded. Both sides look bad...

Link to comment
Share on other sites

Two lines:

Disable Task Manager

RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System","DisableTaskMgr","REG_DWORD","1")

Enable Task Manager

RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System","DisableTaskMgr","REG_DWORD","0")
Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

Two lines:

Disable Task Manager

RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System","DisableTaskMgr","REG_DWORD","1")

Enable Task Manager

RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System","DisableTaskMgr","REG_DWORD","0")
Ive got taskmgr disabled and re enabling just fine, its the start menu flashing that is the problem. if you hit ctrl alt del with taskmgr disabled, it gives you a popup that tells you its disabled. i put in a little script to get rid of that too, but when it closes it flashes the start menu, which you can bypass the lock from.

And yes i tried the timer, for whatever reason, it didn't work either.

Christianity: In the beginning, there was God, who always was there and created everything.Atheism: In the beginning, there was nothing, which exploded. Both sides look bad...

Link to comment
Share on other sites

I tried the timer in something like this and it worked.

#include <Timers.au3>
#include <Misc.au3>

AdlibEnable("Disable",50)

Dim $time, $diff, $limit

While 1
    $diff = _Timer_Diff($time)
    ToolTip($diff)
WEnd

Func _Start()
    $time = _Timer_Init()
EndFunc

Func Disable()
    If _IsPressed("11") = 1 Then
        $limit += 1
        _Start()
        BlockInput(1)
        MsgBox(48,"Error","That key is not allowed. Input has been blocked for " & $limit & " minutes.",10)
        AdlibDisable()
        AdlibEnable("Enable",50)
    EndIf
EndFunc

Func Enable()
    If $diff >= ($limit * 60000) Then
        BlockInput(0)
        Send("{CTRLDOWN}")
        Send("{CTRLUP}")
        $diff = 0
        AdlibDisable()
        AdlibEnable("Disable",50)
    Endif
EndFunc

That works but there's a problem. When the input is blocked the key doesn't register as being unpressed. You need to press the key again when the message box is present or it will disable input again. I tried sending CTRLUP but it didn't work. That could also be causing your problem with your original approach.

Edit: idea! Maybe send CTRLDOWN and then CTRLUP to register the key as unpressed? I can't test this at the moment but it's worth a shot.

Edit 2: Changed the code to a fully functional example.

Edited by dbzfanatic
Link to comment
Share on other sites

I tried the new timer, still didnt work. Ill include the whole massive thing at the end, just to see if anyone knows why. im starting to lose hope haha

However,

I had an idea to block the special keys. does anyone know how to edit the driver for the keyboard? I found the drivers, but I cant open them and see anything worthwhile. there is a little bit that says it WONT open in DOS, but it is an old dos file, so I'm not quite sure how to do it. If I could just edit the driver file when the script starts and then change it back when it closes it'd work beautifully. I just need to figure out how to edit the file...

CODE
#include <GUIConstants.au3>

#include <windowsconstants.au3>

#include <editconstants.au3>

#include <Audio.au3>

#Include <Misc.au3>

#Include <Timers.au3>

RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\system","DisableTaskMgr","REG_DWORD",1)

Global $pass = IniRead(@ProgramFilesDir & "\AutoIt3\Scripts\Lockout\pass.ini", "Password", "pass", "autoit")

ConsoleWrite($pass & @CRLF)

Global $restore = False, $passed = False

$GUI = GUICreate("PC-Lock", @DesktopWidth, @DesktopHeight, 0, 0, BitOR($WS_POPUP, $WS_CLIPSIBLINGS), $WS_EX_TOPMOST)

$Label1 = GUICtrlCreateLabel("Please enter the correct password before entering the PC", @desktopwidth/2 - 100, @desktopheight/2 - 92, 277, 17)

$Label2 = GUICtrlCreateLabel("Password: ", @desktopwidth/2 - 100,@desktopheight/2 - 52, 56, 17)

$password = GUICtrlCreateInput("", @desktopwidth/2 - 36, @desktopheight/2 - 52, 217, 21)

$submit = GUICtrlCreateButton("Submit", 100 + @desktopwidth/2, @desktopheight/2 - 28, 73, 25, 0)

$okbutton = GUICtrlCreateButton("OK", 100 + @desktopwidth/2, 76 + @desktopheight/2, 73, 25, 0)

$Label3 = GUICtrlCreateLabel("Original: ", @desktopwidth/2 - 100, 20 + @desktopheight/2, 45, 17)

$Label4 = GUICtrlCreateLabel("New: ", @desktopwidth/2 - 100, 52 + @desktopheight/2, 32, 17)

$oldpw = GUICtrlCreateInput("",@desktopwidth/2 - 36, 20 + @desktopheight/2, 217, 21)

$newpw = GUICtrlCreateInput("",@desktopwidth/2 - 36, 52 + @desktopheight/2, 217, 21)

$setnewpw = GuiCtrlCreateButton("Set New Password", 100, 100, 73, 25)

$startvol = _SoundGetMasterVolume()

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

_SoundSetMasterVolume(0)

#cs

AdlibEnable("Disable",50)

Dim $time, $diff, $limit

While 1

$diff = _Timer_Diff($time)

ToolTip($diff)

WEnd

Func _Start()

$time = _Timer_Init()

EndFunc

Func Disable()

If _IsPressed("11") = 1 Then

$limit += 1

_Start()

BlockInput(1)

MsgBox(48,"Error","That key is not allowed. Input has been blocked for " & $limit & " minutes.",10)

AdlibDisable()

AdlibEnable("Enable",50)

EndIf

EndFunc

Func Enable()

If $diff >= ($limit * 60000) Then

BlockInput(0)

Send("{CTRLDOWN}")

Send("{CTRLUP}")

$diff = 0

AdlibDisable()

AdlibEnable("Disable",50)

Endif

EndFunc

#ce

While 1

$nMsg = GUIGetMsg()

;Select

; Case _IsPressed("11") = 1

; $ctrlpress = True

; Case _IsPressed("11") = 0

; $ctrlpress = False

;Case _IsPressed("12") = 1

; $altpress = True

;Case _IsPressed("12") = 0

; $altpress = False

;EndSelect

;If ($ctrlpress = True) Or ($altpress = True) Then

; BlockInput(1)

;ElseIf ($ctrlpress = False) And ($altpress = False) Then

; BlockInput(0)

;EndIf

If WinExists("Task Manager", "Task Manager has been disabled by your administrator") Then

WinKill("Task Manager", "Task Manager has been disabled by your administrator")

EndIf

Switch $nMsg

Case $GUI_EVENT_CLOSE

If $passed Then Exit

Case $submit

$entered = GUICtrlRead($password)

If $pass == $entered Then

RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\system","DisableTaskMgr","REG_DWORD",0)

_SoundSetMasterVolume($startvol)

Exit

$passed = True

Else

MsgBox(0, "Fail", "Fail")

EndIf

Case $okbutton

If $passed Then

$old = GUICtrlRead($oldpw)

$new = GUICtrlRead($newpw)

If $old == $pass Then

IniWrite(@ProgramFilesDir & "\pass.ini", "Password", "pass", $new)

MsgBox(0, "Done!", "Now please re-open PC-Lock")

Exit

Else

MsgBox(0, "Fail", "The original password does not match.")

EndIf

EndIf

;Case $setnewpw

;MsgBox("", "test", "test")

; GUICreate("Set New Password", 200, 200, @desktopwidth/2 -100, @desktopheight/2 -100, $WS_CHILD, $WS_EX_TOPMOST)

;

EndSwitch

If $restore Then

$restore = False

WinActivate($GUI)

WinSetOnTop($GUI, "", 1)

EndIf

WEnd

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)

Local $iCode = BitShift($wParam, 16)

Switch $lParam

Case GUICtrlGetHandle($password)

Switch $iCode

Case $EN_KILLFOCUS

Local $attempt = GUICtrlRead($password)

If Not $passed And $attempt <> $pass Then

$restore = True

GUICtrlSetState($password, $GUI_FOCUS)

EndIf

EndSwitch

EndSwitch

Return $GUI_RUNDEFMSG

EndFunc ;==>WM_COMMAND

sorry, this is about the messiest code ive ever done, but i left it unedited to see if maybe anything's conflicting, etc.

Christianity: In the beginning, there was God, who always was there and created everything.Atheism: In the beginning, there was nothing, which exploded. Both sides look bad...

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