2011-10-18 53 views
9

使Windows .NET應用程序成爲唯一可以在計算機上使用的程序的最佳方式是什麼? 我遇到了定時器或事件來將窗口切換回窗口,使用匹配的文本和一些api32調用將窗體設置爲最頂層。使.NET應用程序成爲唯一可運行的程序?

是否有可能使窗口鎖定屏幕的應用程序,除了屏幕上什麼都不能做什麼事情?我想阻止用戶做其他事情,只讓管理員進入桌面。

+2

我作爲一個用戶,會發現這樣的電腦沒什麼用:-)能夠運行一個應用程序的計算機。我會感到無聊:-) –

+3

@DarinDimitrov:我認爲這可能是某種類型的收銀軟件或類似的東西。就像一個亭子。 –

+1

你的意思是沿[kiosk模式](http://stackoverflow.com/questions/4617303/does-windows-7-have-a-kiosk-mode)的行? – R0MANARMY

回答

1

我發現了一個更簡單的方法來做到這一點,不使用kiosk模式或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")` 

Watch my software boot as if it owns windows!

Want to understand more how it works in the full apscect?

11

您需要在Kiosk模式下運行您的應用程序。

外部方法

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

隱藏任務欄kiosk模式

// 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

+0

是好 - 我想這是最好的答案,但我實際上要使用評論中提供的鏈接到PDF如何更改defautl殼程序 - 做所有的代碼不會是必要的,如果用戶想要桌面,我從我的「shell」應用程序運行explorer shell,一切都很好。感謝您的好評! – ppumkin

4

如果你的目的是永久阻止這個指定的用戶,則可以通過管理該適當的組策略。

例如,在本地組策略編輯器(開始菜單gpedit.msc),去本地計算機策略→用戶配置管理模板→系統。你會發現兩個選項:

  • 不要運行指定的Windows應用程序
  • 只運行指定的Windows應用程序

當然,你所要做的組策略的精細化管理,以限制其他的事情對於指定的用戶,防止更改配置,重新啓動機器等。而且您還必須通過鍵盤掛鉤使應用程序阻止特殊鍵。

請記住:不僅僅依賴鉤子,全屏模式和其他防止用戶超出應用程序的東西。如果你這樣做,有一天你的應用程序會崩潰,給用戶無限制的訪問底層操作系統,文件系統等。

相關問題