c#程序ctrl-alt-del屏幕Windows 7

问题描述:

在Windows 7中,当您按ctrl-alt-del时,您将转到另一个屏幕,显示用于显示任务管理器,注销等的选项.
如何按类似于ctrl-alt-del的代码编写代码,使窗口看起来像这样?

Hi In Windows 7 when you press ctrl-alt-del it takes you to a different screen showing you options to display task manager, logoff etc.
how can I code something that is simlar to when you press ctrl-alt-del so that the window looks like that ?

您无法在Ctrl+Alt+Del上执行类似的操作.

此关键事件不会被路由到您的应用程序,因此您无法对其进行拦截.您可以使用任何接近的东西,但绝对不能这样.进行此有趣的排除是为了防止任何软件破坏Ctrl+Alt+Del Windows安全功能.

可能您还需要一个售货亭.
请参阅: http://helpdeskgeek.com/how-to/how-to-setup-windows-vista-and-7-as-a-kiosk/ [ http://en.lmgtfy.com/?q=%22Windows+ 7%22 + kiosk + mode [
You cannot do anything like that on Ctrl+Alt+Del.

This key event will not be routed to your application, so you cannot intercept it. You can use anything close, but never exactly this. This interesting exclusion is done to prevent any software to break Ctrl+Alt+Del Windows Security functionality.

Probably you need a kiosk more.
See this: http://helpdeskgeek.com/how-to/how-to-setup-windows-vista-and-7-as-a-kiosk/[^].

You can also Google http://en.lmgtfy.com/?q=%22Windows+7%22+kiosk+mode[^].

—SA


您是说要让窗口看起来像Windows Ctrl-Alt-Del屏幕吗?如果是这样,我只能假设您是在试图欺骗某人,使他们认为自己的所作所为实际上不是在做,这就是所谓的骇客入侵,我们不容忍或主张那样做实践.如果我错了,请纠正我.
Are you saying you want a window to look like the Windows Ctrl-Alt-Del screen? If so, I can only assume that you''re trying to trick someone into thinking ther''re doing that they''re not actually doing, and that''s called hacking, and we don''t condone or advocate that practice. Correct me if I''m wrong.


您好,会员7654832,

这是为您提供的部分解决方案:应该压住Alt + F4,Windows-Key等,但是不能压住Ctrl + Alt + Del:doh:也许它会为您指明正确的方向……顺便说一句. 覆盖" Ctrl + Alt + Key热键是不可能的(或者我不知道怎么做),所以我错了.

我无法(迅速)发现我的框架提供者如何压制所有键盘输入.但是我做了以下操作:(钩子类摘自本文上的帖子一个简单的C#全局低级键盘挂钩 [ ^ ])

Hi Member 7654832,

Here is a partial solution for you: It should surpress Alt+F4, Windows-Key etc., But it doesn''t surpress Ctrl+Alt+Del :doh: But maybe it points you in the right direction... Btw. "overriding" the Ctrl+Alt+Key hotkey wasn''t possible (or I dont know how), so I was wrong on that.

I couldn''t find out (quickly) how my framework provider surpressed all keyboard input. But I did the following: (The hook class is taken from my post on this article A Simple C# Global Low Level Keyboard Hook[^])

using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;

using System.Windows.Forms;

namespace IWillNotGoAway
{
    static class Program
    {
        static void Main()
        {
            Form form = new Form();
            form.ControlBox = false;
            form.TopMost = true;
            form.FormBorderStyle = FormBorderStyle.None;
            form.Size = Screen.PrimaryScreen.Bounds.Size;
            form.Click += new EventHandler(delegate(object sender, EventArgs e)
            {
                form.Close();
            });

            GlobalKeyboardHook hook = new GlobalKeyboardHook();
            hook.KeyDown += new KeyEventHandler(hook_KeyDown);
            hook.Hook();

            Application.Run(form);
        }

        static void hook_KeyDown(object sender, KeyEventArgs e)
        {
            e.SuppressKeyPress = true;
            e.Handled = true;
        }
    }

    #region CLASS GlobalKeyboardHook

    /// <summary>
    /// Helper class for global (system-wide) keyboard hooks.
    /// </summary>
    public class GlobalKeyboardHook
    {
        #region TYPES

        #region CLASS KeyboardHookStruct

        /// <summary>
        /// Marshalling of the Windows-API KBDLLHOOKSTRUCT structure.#
        /// Contains information about a low-level keyboard input event.
        /// This is named "struct" to be consistent with the Windows API name,
        /// but it must be a class since it is passed as a pointer in SetWindowsHookEx.
        /// </summary>
        [StructLayout(LayoutKind.Sequential)]
        class KeyboardHookStruct
        {
            public int vkCode;
            public int scanCode;
            public int flags;
            public int time;
            public int dwExtraInfo;
        }

        #endregion // CLASS KeyboardHookStruct

        #region DELEGATE HookProc

        /// <summary>
        /// Represents the method called when a hook catches a monitored event.
        protected delegate int HookProc(int nCode, int wParam, IntPtr lParam);

        #endregion // DELEGATE HookProc

        #endregion // TYPES

        #region CONSTANTS

        const int WH_KEYBOARD_LL = 13;
        const int WH_KEYBOARD = 2;

        const int WM_KEYDOWN = 0x100;
        const int WM_KEYUP = 0x101;
        const int WM_SYSKEYDOWN = 0x104;
        const int WM_SYSKEYUP = 0x105;

        const byte VK_SHIFT = 0x10;
        const byte VK_CAPITAL = 0x14;
        const byte VK_NUMLOCK = 0x90;

        const byte VK_LSHIFT = 0xA0;
        const byte VK_RSHIFT = 0xA1;
        const byte VK_LCONTROL = 0xA2;
        const byte VK_RCONTROL = 0x3;
        const byte VK_LALT = 0xA4;
        const byte VK_RALT = 0xA5;

        // const byte LLKHF_ALTDOWN = 0x20; // not used

        #endregion // CONSTANTS

        #region VARIABLES

        /// <summary>
        /// Value indicating if hook is active.
        /// </summary>
        bool m_bHookActive;

        /// <summary>
        /// Stored hook handle returned by SetWindowsHookEx
        /// </summary>
        int m_iHandleToHook;

        /// <summary>
        /// Stored reference to the HookProc delegate (to prevent delegate from beeing collected by GC!)
        /// </summary>
        protected HookProc m_hookproc;

        #endregion // VARIABLES

        #region EVENTS

        /// <summary>
        /// Occurs when a key is pressed.
        /// </summary>
        public event KeyEventHandler KeyDown;
        /// <summary>
        /// Occurs when a key is released.
        /// </summary>
        public event KeyEventHandler KeyUp;
        /// <summary>
        /// Occurs when a character key is pressed.
        /// </summary>
        public event KeyPressEventHandler KeyPress;

        #endregion // EVENTS

        #region CONSTRUCTION & DESTRUCTION

        /// <summary>
        /// Dtor.
        /// </summary>
        ~GlobalKeyboardHook()
        {
            Unhook();
        }

        #endregion // CONSTRUCTION & DESTRUCTION

        #region PROPERTIES

        /// <summary>
        /// Gets a value indicating if hook is active.
        /// </summary>
        public bool HookActive
        {
            get { return m_bHookActive; }
        }

        #endregion // PROPERTIES

        #region METHODS

        /// <summary>
        /// Install the global hook.
        /// </summary>
        /// <returns> True if hook was successful, otherwise false. </returns>
        public bool Hook()
        {
            if(!m_bHookActive)
            {
                m_hookproc = new HookProc(HookCallbackProcedure);

                IntPtr hInstance = GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName);
                m_iHandleToHook = SetWindowsHookEx(
                    WH_KEYBOARD_LL,
                    m_hookproc,
                    hInstance,
                    0);

                if(m_iHandleToHook != 0)
                {
                    m_bHookActive = true;
                }
            }
            return m_bHookActive;
        }

        /// <summary>
        /// Uninstall the global hook.
        /// </summary>
        public void Unhook()
        {
            if(m_bHookActive)
            {
                UnhookWindowsHookEx(m_iHandleToHook);
                m_bHookActive = false;
            }
        }

        /// <summary>
        /// Raises the KeyDown event.
        /// </summary>
        /// <param name="kea"> KeyEventArgs </param>
        protected virtual void OnKeyDown(KeyEventArgs kea)
        {
            if(KeyDown != null)
                KeyDown(this, kea);
        }

        /// <summary>
        /// Raises the KeyUp event.
        /// </summary>
        /// <param name="kea"> KeyEventArgs </param>
        protected virtual void OnKeyUp(KeyEventArgs kea)
        {
            if(KeyUp != null)
                KeyUp(this, kea);
        }

        /// <summary>
        /// Raises the KeyPress event.
        /// </summary>
        /// <param name="kea"> KeyEventArgs </param>
        protected virtual void OnKeyPress(KeyPressEventArgs kpea)
        {
            if(KeyPress != null)
                KeyPress(this, kpea);
        }

        #endregion // METHODS

        #region EVENTHANDLER

        /// <summary>
        /// Called when hook is active and a key was pressed.
        /// </summary>
        int HookCallbackProcedure(int nCode, int wParam, IntPtr lParam)
        {
            bool bHandled = false;

            if(nCode > -1 && (KeyDown != null || KeyUp != null || KeyPress != null))
            {
                // Get keyboard data
                KeyboardHookStruct khs = (KeyboardHookStruct) Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct));

                // Get key states
                bool bControl = ((GetKeyState(VK_LCONTROL) & 0x80) != 0) || ((GetKeyState(VK_RCONTROL) & 0x80) != 0);
                bool bShift = ((GetKeyState(VK_LSHIFT) & 0x80) != 0) || ((GetKeyState(VK_RSHIFT) & 0x80) != 0);
                bool bAlt = ((GetKeyState(VK_LALT) & 0x80) != 0) || ((GetKeyState(VK_RALT) & 0x80) != 0);
                bool bCapslock = (GetKeyState(VK_CAPITAL) != 0);

                // Create KeyEventArgs
                KeyEventArgs kea = new KeyEventArgs((Keys) (khs.vkCode |
                        (bControl ? (int) Keys.Control : 0) |
                        (bShift ? (int) Keys.Shift : 0) |
                        (bAlt ? (int) Keys.Alt : 0)));

                // Raise KeyDown/KeyUp events
                if(wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN)
                {
                    OnKeyDown(kea);
                    bHandled = kea.Handled;
                }
                else if(wParam == WM_KEYUP || wParam == WM_SYSKEYUP)
                {
                    OnKeyUp(kea);
                    bHandled = kea.Handled;
                }

                // Raise KeyPress event
                if(wParam == WM_KEYDOWN && !bHandled && !kea.SuppressKeyPress)
                {
                    byte[] abyKeyState = new byte[256];
                    byte[] abyInBuffer = new byte[2];
                    GetKeyboardState(abyKeyState);

                    if(ToAscii(khs.vkCode, khs.scanCode, abyKeyState, abyInBuffer, khs.flags) == 1)
                    {
                        char chKey = (char) abyInBuffer[0];
                        if((bCapslock ^ bShift) && Char.IsLetter(chKey))
                            chKey = Char.ToUpper(chKey);
                        KeyPressEventArgs kpea = new KeyPressEventArgs(chKey);
                        OnKeyPress(kpea);
                        bHandled = kea.Handled;
                    }
                }
            }

            if(bHandled)
                return 1;
            else
                return CallNextHookEx(m_iHandleToHook, nCode, wParam, lParam);
        }

        #endregion // EVENTHANDLER

        #region EXTERN

        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
        static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hMod, int dwThreadId);

        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
        static extern int UnhookWindowsHookEx(int idHook);

        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        static extern int CallNextHookEx(int idHook, int nCode, int wParam, IntPtr lParam);

        [DllImport("user32.dll")]
        static extern int GetKeyboardState(byte[] pbKeyState);

        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        static extern short GetKeyState(int vKey);

        [DllImport("user32.dll")]
        static extern int ToAscii(int uVirtKey, int uScanCode, byte[] lpbKeyState, byte[] lpwTransKey, int fuState);

        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr GetModuleHandle(string lpModuleName);

        #endregion // EXTERN
    }

    #endregion // CLASS GlobalKeyboardHook
}