sendMessage 函数
吃饭回来写。

解决方案 »

  1.   

    system.windows.forms.sendkey去看看这个方法吧  不用调用api那么麻烦的
      

  2.   

    个人认为系统特定按键系列(象Ctl+Alt+Del)并不容易模拟,特别是运行Vista的时候。
    以下代码并没有发送WIN+L按键,只是断开当前会话而不结束它,效果象。
    using System;
    using System.Runtime.InteropServices;class Program
    {
        static void Main()
        {
            int sessionID = WTSGetActiveConsoleSessionId();
            WTSDisconnectSession(IntPtr.Zero, sessionID, false);
        }    [DllImport("Wtsapi32.dll")]
        static extern bool WTSDisconnectSession(IntPtr hServer, int SessionID, bool bWait);    [DllImport("Kernel32.dll")]
        static extern int WTSGetActiveConsoleSessionId();
    }
      

  3.   

    老纳没看清楚
    ..
    sendmessage
    无法实现
    可以使用   [DllImport("user32")]
            public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);   调用..
                  const byte VK_LWIN = 0x5B;
                const byte VK_D = 0x44;
                const int KEYEVENTF_KEYUP = 0x02;
                const byte VK_L = 0x4C; 
                keybd_event(VK_LWIN, 0, 0, 0);//发送lwin
                keybd_event(VK_L, 0, 0, 0);//发送l
                keybd_event(VK_L, 0, KEYEVENTF_KEYUP, 0);
                keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);   
      

  4.   

    sendkey.send..
    不支持对win键的操作...
    组合键只有 shift,ctrl alt三个
    详细查询msdn
      

  5.   

    我的环境只是XP 不需要考虑Vista 不过听说Vista里面这样是发送不了的吧
      

  6.   

    不要100样就想到模拟按键,测试下面代码using System;
    namespace ConsoleApplication2
    {
        class Program
        {
            static void Main(string[] args)
            {
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.WorkingDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.System);
                p.StartInfo.FileName = "rundll32.exe";
                p.StartInfo.Arguments = "user32.dll,LockWorkStation";
                p.Start(); 
            }
        }
    }