Link to home
Start Free TrialLog in
Avatar of crystalsoft
crystalsoft

asked on

How to Lock "Alt + Tab" key

Hello experts
I want to lock Alt + Tab key how can i do that using registry edit

Thanks
Avatar of milindsm
milindsm
Flag of India image

HKEY_CURRENT_USER\Control Panel\Desktop

Key  Coolswitch
1 enable switching
0 disable switching

You may have to restart the machine
Avatar of crystalsoft
crystalsoft

ASKER


Thanks Experts

milindsm:   i followed your suggestion but its Not getting what i want (Lock "Alt + Tab")

K4U:   can you Please provide me following code in vb6 (I get this from your suggested link)
''''''''''''''''''''
LRESULT CALLBACK NewSASWindowProc(HWND hWnd, UINT uMsg,
  WPARAM wParam, LPARAM lParam)
{
  if (uMsg == WM_HOTKEY)
  {
     // Ctrl+Alt+Del

     if (lparam == MAKELONG(MOD_CONTROL | MOD_ALT, VK_DELETE))
  return 1;
  }
  return CallWindowProc(OldSASWindowProc, hWnd, wParam, lParam);
}
'''''

Is there any other way to lock alt+tab (like Registry edit)
Avatar of Daniel Van Der Werken
Looks like the registry setting for this is documented here:
http://msdn.microsoft.com/en-us/magazine/cc188951.aspx
Of note:

Key:
HKCU HKEY_CURRENT_USER\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System

Value:
DisableTaskMgr

Setting:  One of the following:
DWORD
      TASKMGR  = 0x01,  // disable task manager (Ctrl+Alt+Del)
      TASKKEYS = 0x02,  // disable task keys (Alt-TAB, etc)
      TASKBAR  = 0x04,  // disable task bar
      ALL=0xFFFF        // disable everything :(
I don't have access to my local system to test (not admin so I can't create the System key).  See if setting the DWORD value to 0x00000002 works.

Dan7el:

Case 1
    nDrives = 2
   
    wshShell.regwrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableTaskMgr", CLng(nDrives), "REG_DWORD"

Not working
Did you reboot or restart the shell?

Reboot with the setting.  See if it works.

No i didnt restarted , But i am using following code instead of restart system
 
 Dim bogus As Long
  Call SendMessageTimeoutA( _
    HWND_BROADCAST, _
    WM_SETTINGCHANGE, _
    0, _
    0, _
    SMTO_NORMAL, _
    1000, _
    bogus)

Actually i don't want to restart system,
When you say "Lock" are you meaning "Disable", so that the user cannot press the CAPS key (you want all input in lower case) or the TAB key (you want the user only to be able to press the spacebar to put spaces in any input).
Or do you perhaps want the CAPS locked ON? (All input is in capitals).
Is this input ONLY for within your program, or do you want it to affect every program running on a machine?
If the answer to the last question is "Yes", then writing to the registry is what is required.
Of course, this is in effect unsound programming since it is doing what "virus"s  often do!

If the changes are only effective within your program (which is what you should be doing, not changing external conditions outside a program without the user knowing it) then that can be done using VB code internal to your program, without rebooting, and I have written some code that does that.

Please advise.
 
Or do you mean "Alt+Tab" together which brings up the "Program switching" functionality external to any program (I gather that is what you are after).
That is a bit more difficulat and certainly requirs work in the registry.
I would not suggest you do this though, since you are basically interfering with the System functionality. Users of the machines may not appreciate this restriction. Still, if that is what you are after, let me know....I am investigating.

Just for my vb application
Not for every windows programms
if form1 is maximized and timer is "00:00:00" User can not go to windows directly using Alt+Tab, first he need to take permission from server or administrator,
after form1 is minimized and timer is not   "00:00:00" then he can use alt+tab.

hope you understand this
You CAN turn off the Alt+Tab key by changing the value in a registry entry from 1 to 0
The key in the registry is "HKEY_CURRENT_USER\Control Panel\Desktop\CoolSwitch"
If the value in it is set to "0" then Alt+Tab is turned off, and if it is set to 1, it is turned back on.
You MUST reboot however after altering it for the setting to come into effect.
This is not advisable though, since if your program "crashes" the user may be left unable to use Alt+Tab again until you run your program again.

That's the bad news....
The good news is the following code does what you want, I think.
It is internal ONLY to your program and prevents the user from switching from the current form (in your program) on the desktop to any other form within your program on your desktop, or from minimizing the form or closing it.
Create a test Project with Two forms.
Form1 has startup position as "Default" , and Form2 as "Centre Screen"
Add a button to Form1  called "cmdShowForm" with the following within Form1
         
      Option Explicit

      Private Sub Form_Load()
        Form1.cmdShowForm.Caption = "Show Form 2"
     End Sub

     Private Sub cmdShowForm_Click()
           Form2.Show vbModal ' must be called as modal to prevent leaving the form
      End Sub
     
   
Add a textbox to Form2 called "txtTimeRemaining" and a "Timer" called "Timer1".
then add the following code to the internals of Form2

You will find that while the timer is counting down you cannot do anything within your program, although the user can still Alt+Tab to outside programs (as he/she should be able to do) , Of course you cannot force the active window in your program to remain on top of other programs...after all, the user can even turn the screen off if they wanted too!
(on a desktop anyway...lol)

This may give you some ideas on tweaking your program ......
Is that what you are after??

Option Explicit
Public dEndTime As Date

Private Sub Timer1_Timer()
  Dim m As Integer
  Dim s As Integer
  Dim h As Integer
  Dim dNow As Date
  dNow = Now
  h = DateDiff("h", dNow, dEndTime)
  m = DateDiff("n", dNow, dEndTime)
  s = DateDiff("s", dNow, dEndTime)
  txtTimeLeft.Text = Format(h, "00") + ":" + Format(m, "00") & ":" & Format(s, "00")
  If txtTimeLeft.Text = "00:00:00" Then
    Timer1.Interval = 0 'turn off timer
    Me.Enabled = True
  End If
End Sub
Private Sub Form_Load()
  dEndTime = DateAdd("s", 10, Now())
  Timer1.Interval = 1000
  Me.Enabled = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
  'just to make sure this cannot happen!
  If Me.txtTimeLeft.Text <> "00:00:00" Then
    Cancel = 1 'stop unload
  End If
End Sub

Open in new window


craisin:
Second suggestion will not work on my situation,

I checked First one but
First one is not working after restart also.
"HKEY_CURRENT_USER\Control Panel\Desktop\CoolSwitch"
and
value i set is 0
then i restarted computer
but still its ALT+TAB is active



Why won't second suggestion work? Do you mean thois is not what you want?
The example works beautifully on my machine.
I mean second suggestion is not what i want.

what i want is
if form 1 windowstate  = 2 (Maximized) then ALT+TAB will not work and if form 1 windowstate = 1 (Minimized) then ALT+TAB will work.

i am developing an application for INTERNET CAFE.

Note: Form1 will minimized when administrator will give access from server.
user can not access without taking permission from administrator or server

hope you understand.
ASKER CERTIFIED SOLUTION
Avatar of crystalsoft
crystalsoft

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@crystalsoft

Why do you want to do this?  (under what context?)
i am developing an application for INTERNET CAFE.
You can use a low level keyboard hook, it's very easy...  Your writing in vb6?  I could give you a vb.net example, if you'd like...

Jake
jake072:   Yeh i am writing in VB6,
 if you have example in vb6 or may be you can check above code i posted in
12/18/09 08:49 PM, ID: 26080943, some times its working and sometime not..

Basically, you want to create a low-level keyboard hook as in here
http://msdn.microsoft.com/en-us/library/ms644990(VS.85).aspx

Then test to see if your app is in foreground as in here
http://msdn.microsoft.com/en-us/library/ms633505(VS.85).aspx

Finally test the WindowState as in here
http://msdn.microsoft.com/en-us/library/ms633518(VS.85).aspx


Jake
Had to do this once myself to "capture" the user until they successfully logged on - so I guess it might be similar.

For me it was quite easy : http://support.microsoft.com/kb/226359 and it was a long time ago (might be able to search Microsoft given this link). It does look like Jake072 has given good links and probably is the updated version of the one I posted...

It would help if you described what you are trying to achieve. Simply saying "INTERNET CAFE" doesnt really describe the process all that well.

I am assuming it is your own Internet Cafe (or being contracted), otherwise it does sound a bit dubious as to what you are trying to achieve.

A lot of internet cafes set up a portal environment where the internet access is redirected to a login page - but sounds like you're not doing just internet.

If you could please explain a bit more, it will help a lot... If you can't explain in more detail, then it might be a bit questionable as to what you are doing (in terms of us helping you if it is not legitimate). So, please take the time to try to clarify the requirement...
I searched the Internet extensively and tried many things, but no success with an XP machine.
Now, if you were running under WindowsNT or versions earlier than XP, there is a solution which involves calls to the function SystemParametersInfo (which is part of the User32.dll")
but Microsoft obviously decided to remove this functions ability to turn off the Alt+Tab hotkey (and the "Alt+Esc" hotkey).
That function actually intercepts key input, and using it you specifiy the key combinatins as a screensaver call, with screensavers temporarily turned off (in other words, reasssigning the interrupt).
The onl;y other solution which others have said works is using the following code. I have simply block copied the code and have not tested it (off interstate for three weeks holiday in about 6 hours, so I will leave it up to you to look through...it may give you ideas).
No guarantees.....Happy Christmas

Option Explicit

' ***********************************
' Author : Imran Zaheer
' Email  : imraanz@mail.com
' Web    : www.imraanz.com
' Y2K
' Module : Contains declarations and functions for
'          vHotKeys.

Public Declare Function RegisterHotKey Lib "User32" (ByVal hwnd As Long, _
    ByVal ID As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
    
Public Declare Function UnregisterHotKey Lib "User32" (ByVal hwnd As Long, _
    ByVal ID As Long) As Long

Declare Function SetWindowLong Lib "User32" Alias "SetWindowLongA" _
    (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Declare Function CallWindowProc Lib "User32" Alias "CallWindowProcA" _
    (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public Const WM_HOTKEY = &H312
Public Const GWL_WNDPROC = -4

Public Const MOD_CTRL = &H2 'This example uses CTRL
Public Const MOD_SHFT = &H4
Public Const MOD_ALT = &H1

' VK_A thru VK_Z are the same as their ASCII equivalents: 'A' thru 'Z'
' VK_0 thru VK_9 are the same as their ASCII equivalents: '0' thru '9'
' and others are listed below

Public Const VK_NUMPAD0 = &H60
Public Const VK_NUMPAD1 = &H61
Public Const VK_NUMPAD2 = &H62
Public Const VK_NUMPAD3 = &H63
Public Const VK_NUMPAD4 = &H64
Public Const VK_NUMPAD5 = &H65
Public Const VK_NUMPAD6 = &H66
Public Const VK_NUMPAD7 = &H67
Public Const VK_NUMPAD8 = &H68
Public Const VK_NUMPAD9 = &H69
Public Const VK_MULTIPLY = &H6A
Public Const VK_ADD = &H6B
Public Const VK_SEPARATOR = &H6C
Public Const VK_SUBTRACT = &H6D
Public Const VK_DECIMAL = &H6E
Public Const VK_DIVIDE = &H6F
Public Const VK_F1 = &H70
Public Const VK_F2 = &H71
Public Const VK_F3 = &H72
Public Const VK_F4 = &H73
Public Const VK_F5 = &H74
Public Const VK_F6 = &H75
Public Const VK_F7 = &H76
Public Const VK_F8 = &H77
Public Const VK_F9 = &H78
Public Const VK_F10 = &H79 ' This example uses F10
Public Const VK_F11 = &H7A ' This example uses F11
Public Const VK_F12 = &H7B ' This example uses F12
Public Const VK_F13 = &H7C
Public Const VK_F14 = &H7D
Public Const VK_F15 = &H7E
Public Const VK_F16 = &H7F
Public Const VK_F17 = &H80
Public Const VK_F18 = &H81
Public Const VK_F19 = &H82
Public Const VK_F20 = &H83
Public Const VK_F21 = &H84
Public Const VK_F22 = &H85
Public Const VK_F23 = &H86
Public Const VK_F24 = &H87

Public glWinRet As Long


' Function : CallbackMsgs
' This functions is used as a parameter in the
' API SetWindowLong(), by AddresOf operator, so as to
' Subclass the form to get the Windows Callback msgs...
Public Function CallbackMsgs(ByVal wHwnd As Long, ByVal wmsg As Long, ByVal wp_id As Long, ByVal lp_id As Long) As Long
    If wmsg = WM_HOTKEY Then
        Call DoFunctions(wp_id)
        CallbackMsgs = 1
        Exit Function
    End If
    CallbackMsgs = CallWindowProc(glWinRet, wHwnd, wmsg, wp_id, lp_id)
End Function


' Sub : DoFunction
' Activated by the Function "CallbackMsgs()" whenever
' a hotkey is pressed.
Public Sub DoFunctions(ByVal vKeyID As Byte)
    ' Important Notes :
    ' Do not include any msgboxes or Modal forms in
    ' this procedure, else if you include then by
    ' pressing the Hotkey twice/thrice the application
    ' will be terminated abnormally.
    '
    ' But if it is a requirement for you to include the
    ' Modal forms or msgbox in this procedure then put
    ' the RegisterHotKey() API before hiding the Form
    ' and put the UnRegisterHotKey() API before Showing
    ' the form.
    
    Form1.Show
    Form1.WindowState = 0
    DoEvents
    ' When the Hotkey is pressed once
    ' check if the Dofunctions() has completed
    ' before the CallbackMsgs().
    ' This check is not required if the form is
    ' minimized in the SysTray ...
    If Form1.Visible = False Then
        Form1.Show
        Form1.WindowState = 0
    End If
    
    Form1.Cls
    
    If vKeyID = 0 Then
        Form1.Label1.Caption = "1st HotKey Pressed !"
    Else
        If vKeyID = 1 Then
            Form1.Label1.Caption = "2nd HotKey Pressed !"
        Else
            Form1.Label1.Caption = "3rd HotKey Pressed !"
        End If
    End If
End Sub

Open in new window

My approach to this (I developed an app which was used in our factory) was to create a user which loaded my app as the shell rather than loading Explorer.

Without Explorer there is no ALT+TAB.

This was set via a group policy.

The app contained the ability to reboot the PC.

@rquadling - nice lateral approach - I like it :)
Thank you.

We also used Kiosk mode for IE and used a touch screen rather than a full keyboard.

Both techniques worked for the factory quite well.

There are tools like http://www.autohotkey.com and http://www.phord.com/keyblock.html look useful and MS has a KB on doing something like this (http://support.microsoft.com/kb/161133)