9

使 Windows .NET 应用程序成为唯一可以在计算机上使用的程序的最佳方法是什么?我遇到了计时器或事件来将窗口切换回具有匹配文本的窗口和一些 api32 调用以使表单成为最重要的。

是否可以制作像 Windows 锁屏这样的应用程序,除了屏幕上的内容之外什么都做不了?我想阻止用户做其他事情,只让管理员进入桌面。

4

3 回答 3

11

您需要在信息亭模式下运行您的应用程序。

外部方法

[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);

常数

//constants for modifier keys
private const int USE_ALT = 1;
private const int USE_CTRL = 2;
private const int USE_SHIFT = 4;
private const int USE_WIN = 8;

//hot key ID tracker
short mHotKeyId = 0;

方法

private void RegisterGlobalHotKey(Keys hotkey, int modifiers)
{
    try
    {
        // increment the hot key value - we are just identifying
        // them with a sequential number since we have multiples
        mHotKeyId++;

        if (mHotKeyId > 0)
        {
            // register the hot key combination
            if (RegisterHotKey(this.Handle, mHotKeyId, modifiers, Convert.ToInt16(hotkey)) == 0)
            {
                // tell the user which combination failed to register -
                // this is useful to you, not an end user; the end user
                // should never see this application run
                MessageBox.Show("Error: " + mHotKeyId.ToString() + " - " +
                    Marshal.GetLastWin32Error().ToString(),
                    "Hot Key Registration");
            }
        }
    }
    catch
    {
        // clean up if hotkey registration failed -
        // nothing works if it fails
        UnregisterGlobalHotKey();
    }
}


private void UnregisterGlobalHotKey()
{
    // loop through each hotkey id and
    // disable it
    for (int i = 0; i < mHotKeyId; i++)
    {
        UnregisterHotKey(this.Handle, i);
    }
}

protected override void WndProc(ref Message m)
{
    base.WndProc(ref m);

    // if the message matches,
    // disregard it
    const int WM_HOTKEY = 0x312;
    if (m.Msg == WM_HOTKEY)
    {
        // Ignore the request or each
        // disabled hotkey combination
    }
}

禁用热键

RegisterGlobalHotKey(Keys.F4, USE_ALT);

// Disable CTRL+W - exit
RegisterGlobalHotKey(Keys.W, USE_CTRL);

// Disable CTRL+N - new window
RegisterGlobalHotKey(Keys.N, USE_CTRL);

// Disable CTRL+S - save
RegisterGlobalHotKey(Keys.S, USE_CTRL);

// Disable CTRL+A - select all
RegisterGlobalHotKey(Keys.A, USE_CTRL);

// Disable CTRL+C - copy
RegisterGlobalHotKey(Keys.C, USE_CTRL);

// Disable CTRL+X - cut
RegisterGlobalHotKey(Keys.X, USE_CTRL);

// Disable CTRL+V - paste
RegisterGlobalHotKey(Keys.V, USE_CTRL);

// Disable CTRL+B - organize favorites
RegisterGlobalHotKey(Keys.B, USE_CTRL);

// Disable CTRL+F - find
RegisterGlobalHotKey(Keys.F, USE_CTRL);

// Disable CTRL+H - view history
RegisterGlobalHotKey(Keys.H, USE_CTRL);

// Disable ALT+Tab - tab through open applications
RegisterGlobalHotKey(Keys.Tab, USE_ALT);

隐藏任务栏

// hide the task bar - not a big deal, they can
// still CTRL+ESC to get the start menu; for that
// matter, CTRL+ALT+DEL also works; if you need to
// disable that you will have to violate SAS and 
// monkey with the security policies on the machine

ShowWindow(FindWindow("Shell_TrayWnd", null), 0);

信息亭模式下的示例表单

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;

public partial class frmKioskStarter : Form
{                
    #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

    #region Modifier Constants and Variables

    // Constants for modifier keys
    private const int USE_ALT = 1;
    private const int USE_CTRL = 2;
    private const int USE_SHIFT = 4;
    private const int USE_WIN = 8;

    // Hot key ID tracker
    short mHotKeyId = 0;

    #endregion

    public frmKioskStarter()
    {
        InitializeComponent();

        // Browser window key combinations
        // -- Some things that you may want to disable --
        //CTRL+A           Select All
        //CTRL+B           Organize Favorites
        //CTRL+C           Copy
        //CTRL+F           Find
        //CTRL+H           View History
        //CTRL+L           Open Locate
        //CTRL+N           New window (not in Kiosk mode)
        //CTRL+O           Open Locate
        //CTRL+P           Print
        //CTRL+R           Refresh
        //CTRL+S           Save
        //CTRL+V           Paste
        //CTRL+W           Close
        //CTRL+X           Cut
        //ALT+F4           Close

        // Use CTRL+ALT+DEL to open the task manager,
        // kill IE and then close the application window
        // to exit

        // Disable ALT+F4 - exit
        RegisterGlobalHotKey(Keys.F4, USE_ALT);

        // Disable CTRL+W - exit
        RegisterGlobalHotKey(Keys.W, USE_CTRL);

        // Disable CTRL+N - new window
        RegisterGlobalHotKey(Keys.N, USE_CTRL);

        // Disable CTRL+S - save
        RegisterGlobalHotKey(Keys.S, USE_CTRL);

        // Disable CTRL+A - select all
        RegisterGlobalHotKey(Keys.A, USE_CTRL);

        // Disable CTRL+C - copy
        RegisterGlobalHotKey(Keys.C, USE_CTRL);

        // Disable CTRL+X - cut
        RegisterGlobalHotKey(Keys.X, USE_CTRL);

        // Disable CTRL+V - paste
        RegisterGlobalHotKey(Keys.V, USE_CTRL);

        // Disable CTRL+B - organize favorites
        RegisterGlobalHotKey(Keys.B, USE_CTRL);

        // Disable CTRL+F - find
        RegisterGlobalHotKey(Keys.F, USE_CTRL);

        // Disable CTRL+H - view history
        RegisterGlobalHotKey(Keys.H, USE_CTRL);

        // Disable ALT+Tab - tab through open applications
        RegisterGlobalHotKey(Keys.Tab, USE_ALT);

        // hide the task bar - not a big deal, they can
        // still CTRL+ESC to get the start menu; for that
        // matter, CTRL+ALT+DEL also works; if you need to
        // disable that you will have to violate SAS and 
        // monkey with the security policies on the machine
        ShowWindow(FindWindow("Shell_TrayWnd", null), 0);
    }

    /// <summary>
    /// Launch the browser window in kiosk mode
    /// using the URL keyed into the text box
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void button1_Click(object sender, EventArgs e)
    {
        System.Diagnostics.Process.Start("iexplore", "-k " + txtUrl.Text);
    }


    private void RegisterGlobalHotKey(Keys hotkey, int modifiers)
    {
        try
        {
            // increment the hot key value - we are just identifying
            // them with a sequential number since we have multiples
            mHotKeyId++;

            if(mHotKeyId > 0)
            {
                // register the hot key combination
                if (RegisterHotKey(this.Handle, mHotKeyId, modifiers, Convert.ToInt16(hotkey)) == 0)
                {
                    // tell the user which combination failed to register -
                    // this is useful to you, not an end user; the end user
                    // should never see this application run
                    MessageBox.Show("Error: " + mHotKeyId.ToString() + " - " +
                        Marshal.GetLastWin32Error().ToString(),
                        "Hot Key Registration");
                }
            }
        }
        catch 
        {
            // clean up if hotkey registration failed -
            // nothing works if it fails
            UnregisterGlobalHotKey();
        }
    }


    private void UnregisterGlobalHotKey()
    {
        // loop through each hotkey id and
        // disable it
        for (int i = 0; i < mHotKeyId; i++)
        {
            UnregisterHotKey(this.Handle, i);
        }
    }

    protected override void WndProc(ref Message m)
    {
        base.WndProc(ref m);

        // if the message matches,
        // disregard it
        const int WM_HOTKEY = 0x312;
        if (m.Msg == WM_HOTKEY)
        {
            // Ignore the request or each
            // disabled hotkey combination
        }
    }

    private void Form1_FormClosed(object sender, FormClosedEventArgs e)
    {
        // unregister the hot keys
        UnregisterGlobalHotKey();

        // show the taskbar - does not matter really
        ShowWindow(FindWindow("Shell_TrayWnd", null), 1);

    }
}

这是一篇您可以查看的文章:
http ://www.c-sharpcorner.com/UploadFile/scottlysle/KioskCS01292008011606AM/KioskCS.aspx

以下是一些要研究的打包软件:
http ://www.kioware.com/productoverview.aspx?source=google&gclid=CPeQyrzz8qsCFZFV7Aod6noeMw

于 2011-10-18T18:52:55.670 回答
4

如果您的意图是永久阻止指定用户,您可以通过适当的组策略进行管理。

例如,在本地组策略编辑器(开始菜单gpedit.msc)中,转到本地计算机策略用户配置管理模板系统。你会发现两个选项:

  • 不要运行指定的 Windows 应用程序
  • 仅运行指定的 Windows 应用程序

当然,您必须对组策略进行精细管理,以限制指定用户的其他操作,防止更改配置、重新启动机器等,您还必须让您的应用程序通过键盘挂钩阻止特殊键。

记住:不要仅仅依靠钩子、全屏模式和其他东西来阻止用户离开你的应用程序。如果你这样做了,有一天你的应用程序会崩溃,让用户可以无限制地访问底层操作系统、文件系统等。

于 2011-10-18T19:01:20.373 回答
1

我找到了一种更简单的方法来做到这一点,而不是使用信息亭模式或 gpedits 或任何类似的东西。

在我的应用程序中,我用这两个该死的简单东西制作了一个按钮 - 没有问题!

我使用 shell.cmd 启动了一次单击应用程序 appref-ms,它很有魅力。

'The logged in user has to be administrator or the app run as administrator once.

My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\IniFileMapping\system.ini\boot", "Shell", "USR:Software\Microsoft\Windows NT\CurrentVersion\Winlogon")

'This will change the shell to your program for THIS LOGGED IN user- after re logon bye bye exploerer shell hello custom app!            

My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "Shell", appPath & "\shell.cmd")`

看着我的软件启动,就好像它拥有 Windows 一样!

想全面了解它的工作原理吗?

于 2011-11-24T14:20:07.040 回答