How to prevent Start menu to open (disable it)

B

bz

Hi,

I need an app to run in kiosk mode, so user will not have access to
start menu and taskbar while the app is running


I was able to hide / show the taskbar with trhe following code when
app starts / exits

(the code is in C#, but please help me with suggestion no matter what
lang you are using)

[DllImport("user32.dll", EntryPoint = "FindWindowA")]
static extern int FindWindow(string lpClassName, string
lpWindowName);


[DllImport("user32.dll")]
static extern int SetWindowPos(int hwnd, int hWndInsertAfter,
int x, int y, int cx, int cy, int wFlags);


const int SWP_HIDEWINDOW = 128;
const int SWP_SHOWWINDOW = 64;


static public void HideTaskbar()
{
int intReturn = FindWindow("Shell_traywnd", "");
SetWindowPos(intReturn, 0, 0, 0, 0, 0, SWP_HIDEWINDOW);
}


static public void ShowTaskbar()
{
int intReturn = FindWindow("Shell_traywnd", "");
SetWindowPos(intReturn, 0, 0, 0, 0, 0, SWP_SHOWWINDOW);
}


But users still can access the start menu with Windows button (or Ctrl
+Esc)
Is there any way to disable start menu too?


Thank you
 
C

Cor Ligthert[MVP]

bz,

If you don't use an installer (and setting shortcuts) it will not be in the
Start menu, however programs running without a start menu are mostly windows
services. However your code is not VB.Net, wrong newsgroup maybe?

Cor
 
B

bz

Hi,

The issue is not about setting a shortcut.
My program should behave like a kiosk application - full screen,
exclusive mode (so to not give users access to other programs while
starting this)
I wrote the code to hide taskbare when app is started, and show it
back when exit. But even w/o taskbar, users can open start menu by
pressing Windows key (or CTRL+ESC) on keyboard
And this is what I want to trap and prevent to happen

Regarding ng's, I know the code I post is C#, but this is not an
issue, I post in this ng in purpose. My app contains several modules,
written in various net languages (C#, VB.Net, and even some in
PHP.NET), so the language is not important, I can translate then it in
any lang I need for a particular project within the solution.
I'm just trying several ng's, maybe someone knows a solution to this.

Thanks
 
A

Armin Zingler

bz said:
Hi,

I need an app to run in kiosk mode, so user will not have access to
start menu and taskbar while the app is running


I was able to hide / show the taskbar with trhe following code when
app starts / exits

(the code is in C#, but please help me with suggestion no matter
what lang you are using)

Instead of using this hack, I would try to find a supported way to suppress
the start menu - if possible. To me this seems to be more like a security or
policy issue. In any case, how to do it is not a VB.Net language related
issue, therefore I'd ask in one of the m.p.win32.programmer.* groups.
Unfortunatelly, I didn't find one that seems to be appropriate at first
sight. I suggest asking in the .UI or .kernel group about /what/ to do.


Armin
 
O

\(O\)enone

bz said:
I need an app to run in kiosk mode, so user will not have access to
start menu and taskbar while the app is running

You can disable the Windows, Alt-Tab, Ctrl-Escape, etc. keyboard
combinations using a low level keyboard hook.

I can tell you how to do it in C++, but I don't know how easy it would be to
translate it to C# or VB.NET. Do managed languages support Win32 API
callbacks?
 
B

bz

I need an app to run in kiosk mode, so user will not have access to
You can disable the Windows, Alt-Tab, Ctrl-Escape, etc. keyboard
combinations using a low level keyboard hook.

I can tell you how to do it in C++, but I don't know how easy it would be to
translate it to C# or VB.NET. Do managed languages support Win32 API
callbacks?

I guess they do, since it is possible to interface with API calls
Please let me know how to do it with low level API keyboard hook, and
I hope I'll find a way to port it in C# or vb.net

Or maybe I'll be able to write a small unmanaged C++ dll, and export a
function to call from C# instead.

Thanks
Bogdan
 
O

\(O\)enone

bz said:
I guess they do, since it is possible to interface with API calls
Please let me know how to do it with low level API keyboard hook, and
I hope I'll find a way to port it in C# or vb.net

Or maybe I'll be able to write a small unmanaged C++ dll, and export a
function to call from C# instead.

This is based on the code found here:

http://msdn.microsoft.com/msdnmag/issues/02/09/CQA/

The callback function:

\\\
LRESULT CALLBACK MyTaskKeyHookLL(int nCode, WPARAM wp, LPARAM lp)
{
KBDLLHOOKSTRUCT *pkh = (KBDLLHOOKSTRUCT *) lp;

if (nCode==HC_ACTION) {
BOOL bCtrlKeyDown =
GetAsyncKeyState(VK_CONTROL)>>((sizeof(SHORT) * 8) - 1);

if ((pkh->vkCode==VK_ESCAPE && bCtrlKeyDown) || // Ctrl+Esc
(pkh->vkCode==VK_TAB && pkh->flags & LLKHF_ALTDOWN) || // Alt+TAB
(pkh->vkCode==VK_ESCAPE && pkh->flags & LLKHF_ALTDOWN)|| // Alt+Esc
(pkh->vkCode==VK_LWIN || pkh->vkCode==VK_RWIN) ||
(pkh->vkCode==0))
{ // Start Menu
return 1; // gobble it: go directly to jail, do not pass go
}
}

return CallNextHookEx(g_hHookKbdLL, nCode, wp, lp);
}
///

Variable to store the hook pointer:

\\\
HHOOK g_hHookKbdLL = NULL; // hook handle
///

Code to install the hook:

\\\
if (!g_hHookKbdLL)
{
g_hHookKbdLL = SetWindowsHookEx(WH_KEYBOARD_LL, MyTaskKeyHookLL, hinst,
0);
}
///

(where hinst is the HINSTANCE handle to your application instance)

To remove the hook:

\\\
if (g_hHookKbdLL != NULL)
{
UnhookWindowsHookEx(g_hHookKbdLL);
g_hHookKbdLL = NULL;
}
///

HTH,
 
B

bz

Thank you.
Regards

This is based on the code found here:

http://msdn.microsoft.com/msdnmag/issues/02/09/CQA/

The callback function:

\\\
LRESULT CALLBACK MyTaskKeyHookLL(int nCode, WPARAM wp, LPARAM lp)
{
KBDLLHOOKSTRUCT *pkh = (KBDLLHOOKSTRUCT *) lp;

if (nCode==HC_ACTION) {
BOOL bCtrlKeyDown =
GetAsyncKeyState(VK_CONTROL)>>((sizeof(SHORT) * 8) - 1);

if ((pkh->vkCode==VK_ESCAPE && bCtrlKeyDown) || // Ctrl+Esc
(pkh->vkCode==VK_TAB && pkh->flags & LLKHF_ALTDOWN) || // Alt+TAB
(pkh->vkCode==VK_ESCAPE && pkh->flags & LLKHF_ALTDOWN)|| // Alt+Esc
(pkh->vkCode==VK_LWIN || pkh->vkCode==VK_RWIN) ||
(pkh->vkCode==0))
{ // Start Menu
return 1; // gobble it: go directly to jail, do not pass go
}
}

return CallNextHookEx(g_hHookKbdLL, nCode, wp, lp);}

///

Variable to store the hook pointer:

\\\
HHOOK g_hHookKbdLL = NULL; // hook handle
///

Code to install the hook:

\\\
if (!g_hHookKbdLL)
{
g_hHookKbdLL = SetWindowsHookEx(WH_KEYBOARD_LL, MyTaskKeyHookLL, hinst,
0);
}
///

(where hinst is the HINSTANCE handle to your application instance)

To remove the hook:

\\\
if (g_hHookKbdLL != NULL)
{
UnhookWindowsHookEx(g_hHookKbdLL);
g_hHookKbdLL = NULL;
}
///

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top