How to disable the Windows Start key of the keyboard ?


Hi all,

I'm developing a special application in MFC. A Real Time Control System with exclusive uses that requires data protection.

Its dialog interface covers the entire screen, so it also hides the Windows bar.

And due to security rules issues, user must not enter to the Operating System beyond than only this application.


So, my question is:

Is there any way to disable the Windows Start key of the keyboard ?

I'll really appreciate some code.


Best regards.
I have no idea. But you can disable it in the OS itself.

https://support.microsoft.com/en-us/help/216893/how-to-enable-or-disable-the-keyboard-windows-key

Since these are registry hacks, you can do this in code by modifying the registry directly with your program, to disable it upon start and enable upon exit if you wanted to do that.

Observation tells me that a lot of little kiosks had specialty rugged keyboards that simply lack the key (they also lack other keys that allow hackery like control). Like the ones where you can register for gifts or look at their corporate stock for items not at the local store etc.

You can also make a full screen program that traps the commands. Its not the same thing, but you CAN spawn windows from a console full screen program. It is tricky to get THAT to look decent, though.

Last edited on

Thank you Jonnin

About you said:

Since these are registry hacks, you can do this in code by modifying the registry directly with your program, to disable it upon start and enable upon exit if you wanted to do that.

yes!.. that's what I want!


Previously, I thought of using a special keyboard that lack these keys (Start, Ctrl, Alt, Tab), also I was thinking to disable it physically, unmounting the keyboard. But nevertheless, it would not be appropriate because the technical maintenance staff who has authorization to access the OS will need it.

Thanks for the link. Ultimately if I do not find the way by program, I will do it by OS.
The disadvantage of this is technical staff will have to do this whole process of change every time when do use it.

The ideal way would be to disable it upon start and back enable upon exit it by code as Jonnin said.

Is there somebody who did it?
Someone can provide me some sample code to modify SO registry hacks ?


Thanks in advance.
Another option is to use hooks, might be less dangerous than using the registry.
http://www.programmersheaven.com/discussion/362851/using-keyboard-hooks-how-do-i-disable-the-windows-key
It depends on where/what/stuff about your setup but most places, the tech staff would only need hands-on access rarely (usually, prefer to cut in over the network) and when they do, either a locked up with the physical CPU box second keyboard or bring a normal KB & swap them would work if you wanted the physical security of a keyboard that lacks the offending keys.

There are tons of free examples on how to make a registry entry and update via code on the web, a search or 2 should bear quick fruit. I don't like the registry and generally avoid it, so I don't have a modern sample, mine all date back to winxp.
Last edited on
Thanks Thomas for the link.

That code seems be suitable for this purpose, but I've been trying all afternoon to implement it, but I got stuck in the LLKeyboardProc function, and I even transcribed it as it is, manually, but it gets error where call it from WindowProc.
Supported by a little more in MSDN I found KeyboardProc but I cannot implement it either because it is not available in properties, nor in messages menu nor in invalidations menu.

How can I implement this callback function by properties being it own of Microsoft?
Try to run this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <windows.h>
#include <tchar.h>
#include <crtdbg.h>

LRESULT CALLBACK LLKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
  PKBDLLHOOKSTRUCT hookstruct;

  if (nCode == HC_ACTION)
  {
    switch (wParam)
    {
    case WM_KEYDOWN: case WM_SYSKEYDOWN:
    case WM_KEYUP: case WM_SYSKEYUP:

      hookstruct = (PKBDLLHOOKSTRUCT)lParam;

      if (hookstruct->vkCode == 91) /* pesky Windows button */
      {
        return 1;
      }
      else
        return CallNextHookEx(NULL, nCode, wParam, lParam);
    }
  }
  return CallNextHookEx(NULL, nCode, wParam, lParam);
}

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
  static HHOOK hook_keys;
  int keycode;

  switch (uMsg)
  {
  case WM_CREATE:
    hook_keys = SetWindowsHookEx(WH_KEYBOARD_LL,
      LLKeyboardProc,((LPCREATESTRUCT)lParam)->hInstance,0);
    return 0;

  case WM_DESTROY:
    UnhookWindowsHookEx(hook_keys);
    PostQuitMessage(0);
    return 0;

  default:
    return DefWindowProc(hwnd, uMsg, wParam, lParam);
  }
}


int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
  TCHAR szClassName[] = _T("Template");
  TCHAR szWindowName[] = _T("Template");
  WNDCLASSEX wc = { 0 };
  MSG messages;
  HWND hWnd;

  wc.lpszClassName = szClassName;
  wc.lpfnWndProc = WindowProc;
  wc.cbSize = sizeof(WNDCLASSEX);
  wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
  wc.hInstance = hInstance;

  _ASSERTE(RegisterClassEx(&wc) != 0);

  hWnd = CreateWindowEx(0, szClassName, szWindowName, WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
    HWND_DESKTOP, 0, hInstance, 0);

  _ASSERTE(::IsWindow(hWnd));

  ShowWindow(hWnd, SW_SHOWMAXIMIZED);
  while (GetMessage(&messages, NULL, 0, 0))
  {
    TranslateMessage(&messages);
    DispatchMessage(&messages);
  }

  return static_cast<int>(messages.wParam);

}
Thank you very much Thomas,

With a few change for adaptation it worked at last!!

Here is my adaptations in case anyone will need it.

Best regards.
------------------------------------------------------

...in myMainClassDlg.h:

HHOOK hook_keys;
virtual LRESULT WindowProc(UINT message,WPARAM wParam,LPARAM lParam);
afx_msg void OnDestroy();


...and, in myMainClassDlg.cpp:

LRESULT CALLBACK LLKeyboardProc(int nCode,WPARAM wParam,LPARAM lParam)
{
PKBDLLHOOKSTRUCT hookstruct;
if(nCode==HC_ACTION)
{
switch(wParam)
{
case WM_KEYDOWN: case WM_SYSKEYDOWN: case WM_KEYUP: case WM_SYSKEYUP:
hookstruct = (PKBDLLHOOKSTRUCT)lParam;
if(hookstruct->vkCode == 91) return 1; //Window key
else return CallNextHookEx(NULL,nCode,wParam,lParam);
}
}
return CallNextHookEx(NULL,nCode,wParam,lParam);
}

LRESULT myMainClassDlg::WindowProc(UINT message,WPARAM wParam,LPARAM lParam)
{
if(message==WM_CREATE)
{
hook_keys=SetWindowsHookEx(WH_KEYBOARD_LL,LLKeyboardProc,((LPCREATESTRUCT)lParam)->hInstance,0); //desactiva tecla Window
return 0;
}
return CDialogEx::WindowProc(message,wParam,lParam);
}

void myMainClassDlg::OnDestroy()
{
CDialogEx::OnDestroy();
UnhookWindowsHookEx(hook_keys);
PostQuitMessage(0);
}
Topic archived. No new replies allowed.