Introduction
This article addresses a simple approach to supporting the display of a Web site in kiosk mode using a simple WinForms application. Kiosk mode is used to display the contents of a Web page without the browser controls visible. The notion for doing something like that is that one can use a Web site to display some specific information to a user without allowing the user to navigate away from the Web site. For example, if one needed to display a building map in the lobby of a business or allow a user to investigate a product line and place a sales order from a mall display, a kiosk might be just the ticket.
Naturally, as with anything, there are problems with keeping a user locked on to a page or set of pages on the site. Most of these are easily handled but the design of the site has to be carefully considered in advance (for example, one would not want to display advertisements that would allow the user to link off to a different Web site). Of course if the user has a keyboard, it might be a good idea to disable certain hot key combinations to prevent the user from opening a new browser window or closing the current browser window. One may even need to violate default security policy on the machine to prevent the user from opening the task manager or start menu. This example addresses disabling hot key combinations that don't violate SAS; however, if it is necessary, one can investigate making registry changes or other alternative methods for disabling CTRL+ALT+DEL and CTRL+ESC including third party controls or the MSGina.DLL (which I understand no longer works with Vista).
A better answer might be to investigate the use of a touch interface, a touch interface virtual keyboard, or a kiosk keyboard that will not permit a user to input such key combinations; the easiest way to keep a user from messing around with the operating system and other applications on the machine is of course to remove the standard keyboard from the equation.
An alternative to kiosk mode Web sites would be to use full screen WinForms applications; the same issues still apply in terms of CTRL+ALT+DEL and CTRL+ESC but they can be managed differently; for example one could use key previews to block certain key combinations from going through.
Figure 1: The demonstration application running.
Figure 2: Displaying a Website in Kiosk Mode.
Getting Started
In order to get started, unzip the included project and open the solution in the Visual Studio 2008 environment. In the solution explorer, you should note these files (Figure 3):
Figure 3: Solution Explorer.
The Main Form (frmKioskStarter.cs)
The main Form is the only form contained in the application; all of the application specific code required to display the Web site in kiosk mode is contained in this Form as is all of the code used to block certain hot key combinations. The code shows how to shut down many of the browser related hot key combinations but does not do anything to violate the default security policies of the machine.
The code is pretty simple. If you'd care to open the code view up in the IDE, you will see that the code file begins as follows:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
The imports are per the default configuration for a Windows application; some unnecessary libraries were omitted, generics were dropped from the collections reference and Interop services was added to the list.
Following the imports, the namespace
and class
are defined:
namespace KioskMode
{
public partial class frmKioskStarter : Form
{
Following the class
declarations, a region
is defined and the DLL imports
needed to alter the global hot keys and to disable the status bar are included:
#region Dynamic Link Library Imports
[DllImport("user32.dll")]
private static extern int FindWindow(string cls, string wndwText);
[DllImport("user32.dll")]
private static extern int ShowWindow(int hwnd, int cmd);
[DllImport("user32.dll")]
private static extern long SHAppBarMessage(long dword, int cmd);
[DllImport("user32.dll")]
private static extern int RegisterHotKey(IntPtr hwnd, int id, int
fsModifiers, int vk);
[DllImport("user32.dll")]
private static extern int UnregisterHotKey(IntPtr hwnd, int id);
#endregion
Following the DLL imports
, another region
is defined and used to contain the modifier key constants and to declare a hot key Id variable; each hot key combination disabled by the application is assigned an ID number (a short) which is also used to remove the hot key restrictions whenever the application is stopped.
#region Modifier Constants and Variables
private const int USE_ALT = 1;
private const int USE_CTRL = 2;
private const int USE_SHIFT = 4;
private const int USE_WIN = 8;
short mHotKeyId = 0;
#endregion
Within the constructor; a series of hot key combinations are disabled to make it a little more difficult to navigate away from the kiosk site.
public frmKioskStarter()
{
InitializeComponent();
RegisterGlobalHotKey(Keys.F4, USE_ALT);
RegisterGlobalHotKey(Keys.W, USE_CTRL);
RegisterGlobalHotKey(Keys.N, USE_CTRL);
RegisterGlobalHotKey(Keys.S, USE_CTRL);
RegisterGlobalHotKey(Keys.A, USE_CTRL);
RegisterGlobalHotKey(Keys.C, USE_CTRL);
RegisterGlobalHotKey(Keys.X, USE_CTRL);
RegisterGlobalHotKey(Keys.V, USE_CTRL);
RegisterGlobalHotKey(Keys.B, USE_CTRL);
RegisterGlobalHotKey(Keys.F, USE_CTRL);
RegisterGlobalHotKey(Keys.H, USE_CTRL);
RegisterGlobalHotKey(Keys.Tab, USE_ALT);
ShowWindow(FindWindow("Shell_TrayWnd", null), 0);
}
The next button click event handler is used to launch a browser window in kiosk mode; passing the k
argument to Internet Explorer is all that is required. The URL entered into the Form’s textbox
is used to identify what page will be opened in Internet Explorer.
private void button1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("iexplore", "-k " +
txtUrl.Text);
}
The next bit of code is used to register a hot key combination; in this instance we are using it to override an existing hot key combination.
private void RegisterGlobalHotKey(Keys hotkey, int modifiers)
{
try
{
mHotKeyId++;
if(mHotKeyId > 0)
{
if (RegisterHotKey(this.Handle, mHotKeyId, modifiers,
Convert.ToInt16(hotkey)) == 0)
{
MessageBox.Show("Error: " +
mHotKeyId.ToString() + " - " +
Marshal.GetLastWin32Error().ToString(),
"Hot Key Registration");
}
}
}
catch
{
UnregisterGlobalHotKey();
}
}
The next method is used to unregister the hot keys set up by the application; this is used to restore normal functioning after the application is closed. The combinations are identified by the hot key ID value stored for each replaced by the application; to disable all of them, this bit of code loops through each ID and disables it:
private void UnregisterGlobalHotKey()
{
for (int i = 0; i < mHotKeyId; i++)
{
UnregisterHotKey(this.Handle, i);
}
}
The next bit of code is used to handle the receipt of a hot key combination whenever the application is running. The code merely disregards all registered hot key combinations.
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
const int WM_HOTKEY = 0x312;
if (m.Msg == WM_HOTKEY)
{
}
}
The last bit of code is called when the Form closes; this code unregisters all of the hot key combinations and shows the taskbar once again.
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
UnregisterGlobalHotKey();
ShowWindow(FindWindow("Shell_TrayWnd", null), 1);
}
Summary
Even though this application shows how to display a Web site in kiosk mode and to disable the browser related hot keys; the application does not violate the security policy. In building a kiosk; it would be best if the user did not have access to a full keyboard or any keyboard at all. If alphanumeric input is required, consideration of the use of custom kiosk keyboards or a virtual keyboard should be considered.