Disabling CTRL-ALT-DEL, ALT-TAB, CTRL-ESC

Windows specific forum
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by lee__48.

I want to write a simple program to lock Windows, as an alternative to a screensaver. I did write a similar program from the Amiga years ago, but it had the problem that you could switch between screens using a keyboard shortcut.

I found the code below on AllAPI.net, it is VB code to disable CTRL-ALT-DEL, ALT-TAB, and CTRL-ESC by tricking Windows into thinking a screensaver is running.

Does anyone know how to do something similar in PureBasic, or perhaps, can convert the code below. I would prefer to keep CTRL-ALT-DEL. I have code to remove the program from the CTRL-ALT-DEL list. It could prove slightly safer to keep the CTRL-ALT-DEL incase the program crashes!

Cheers,
Lee.

Private Const SPI_SCREENSAVERRUNNING = 97&
Private Declare Function SystemParametersInfo Lib "User32" _
Alias "SystemParametersInfoA" _
(ByVal uAction As Long, _
ByVal uParam As Long, _
lpvParam As Any, _
ByVal fuWinIni As Long) As Long

Private Sub Form_Load()
Command1.Caption = "Disabled"
Command2.Caption = "Enabled"
End Sub

Private Sub Form_Unload(Cancel As Integer)
'Re-enable CTRL+ALT+DEL and ALT+TAB before the program terminates.
Command2_Click
End Sub

Private Sub Command1_Click()
Dim lngRet As Long
Dim blnOld As Boolean
lngRet = SystemParametersInfo(SPI_SCREENSAVERRUNNING, True, _
blnOld, 0&)
End Sub

Private Sub Command2_Click()
Dim lngRet As Long
Dim blnOld As Boolean
lngRet = SystemParametersInfo(SPI_SCREENSAVERRUNNING, False, _
blnOld, 0&)
End Sub
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Voldemort.

That code only works with Windows 95, 98 and Me. It doesn't apply to Windows NT, 2000 and XP. So is it really worth using?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by lee__48.
Originally posted by Voldemort

That code only works with Windows 95, 98 and Me. It doesn't apply to Windows NT, 2000 and XP. So is it really worth using?
It would be alright for me as I use 98, but it would be no good if i wanted to distribute it :(

Lee
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Post by Danilo »

Password iss "123".

Code: Select all

;
; by Danilo, Posted - 26 Sep 2002 :  03:14:34  (engl. forum)
;

; merendo,
; 
; on winNT/2000/XP no program is allowed To
; block the CTRL+ALT+DEL, because this would
; be a security risc.
; Every program could block CTRL+ALT+DEL And
; do what it wants... And the user couldnt stop
; it anymore.
; 
; If you use Windows98, you can do it by telling
; windows your app is a screensaver.
; 
; This code disables ALT+TAB, ATL+ESC, And Windows-Keys...
; ...also on Win2000:



; The line " SystemParametersInfo_( #SPI_SCREENSAVERRUNNING, 1, @Dummy, 0) "
; is For Windows 9x Systems.
; It tells Windows that a screensaver is running, so it blocks
; all other input on Win9x.
SystemParametersInfo_( #SPI_SCREENSAVERRUNNING, 1, @Dummy, 0);



OpenLibrary(1,"kernel32.dll")
CallFunction(1,"RegisterServiceProcess", GetCurrentProcessID_(), 1 )
  
Structure KBDLLHOOKSTRUCT
  vkCode.l
  scanCode.l
  flags.l
  time.l
  dwExtraInfo.l
EndStructure

Global hook
  
Procedure.l myKeyboardHook(nCode, wParam, *p.KBDLLHOOKSTRUCT)
   If nCode = #HC_ACTION
      If wParam = #WM_KEYDOWN Or wParam = #WM_SYSKEYDOWN Or wParam = #WM_KEYUP Or wParam = #WM_SYSKEYUP
         #LLKHF_ALTDOWN = $20
         If ((*p\vkCode = #VK_TAB) And (*p\flags & #LLKHF_ALTDOWN)) Or ((*p\vkCode = #VK_ESCAPE) And (*p\flags & #LLKHF_ALTDOWN)) Or ((*p\vkCode & #VK_ESCAPE) And (GetKeyState_(#VK_CONTROL) & $8000)) ;Or 
            ProcedureReturn 1
         ElseIf (*p\vkCode = #VK_LWIN) Or (*p\vkCode = #VK_RWIN)
            ProcedureReturn 1
         EndIf
       EndIf
    EndIf
;beep_(800,1)
ProcedureReturn CallNextHookEx_(hook, nCode, wParam, lParam)
EndProcedure
  
  
; Win NT
#WH_KEYBOARD_LL = 13
hook = SetWindowsHookEx_(#WH_KEYBOARD_LL,@myKeyboardHook(),GetModuleHandle_(0),0)
;If hook = 0: End: EndIf
  
hWnd = OpenWindow(1,10,10,100,100,#PB_Window_BorderLess,"")
       ShowWindow_(hWnd, #SW_MAXIMIZE)
       SetWinBackgroundColor(hWnd,0)
  
       CreateGadgetList(hWnd)
       hString = StringGadget(1,GetSystemMetrics_(#SM_CXSCREEN)/2-100/2, GetSystemMetrics_(#SM_CYSCREEN)/2,100,20,"Enter Password",#PB_String_Numeric)
  
       SetFocus_(hString)
       GetWindowRect_(hString, winrect.RECT)
       ;SetThreadPriority_(GetCurrentThread_(),#REALTIME_PRIORITY_CLASS)
  
Repeat
   Message = WindowEvent()
             SetActiveWindow_(hWnd)
             SetWindowPos_(hWnd,#HWND_TOPMOST,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE)
             ClipCursor_(winrect)
             SendMessage_(hstring,#WM_KEYDOWN,#VK_END,0)
             SetFocus_(hString)
   If Message
      Select Message
         Case #PB_EventGadget
             Select EventGadgetID()
                Case 1
                     If GetGadgetText(1) = "123"
                        UnhookWindowsHookEx_(hook)
                        ClipCursor_(0)
                        SystemParametersInfo_( #SPI_SCREENSAVERRUNNING, 0, @Dummy, 0);
                        End
                     EndIf
             EndSelect
      EndSelect
   Else
      Delay(1)
   EndIf
ForEver

; But CTRL+ALT+DEL can on win2000 only be disabled
; by writing a lowlevel system device driver For the keyboard.
; Info about this should be in the MS DDK.
; 
; Best way For you would be To install win98
; on your disco machine... 
; 
; cya,
; ...Danilo
; 
; (registered PureBasic user)
; 
cya,
...Danilo
...:-=< http://codedan.net/work >=-:...
-= FaceBook.com/DaniloKrahn =-
Post Reply