开机没办法 除非你写bios
登录有办法 通过gina
注销        hook ExitWindow之类的函数

解决方案 »

  1.   

    我知道关机,重起,注销时系统会发WM_QUERYENDSESSION 和 WM_ENDSESSION消息。
    请问login 和 logoff有什么特殊的消息?
      

  2.   

    logoff 不就是关机重启注销中的一种
    login会有什么消息不知道
      

  3.   

    hook BOOL WINAPIExitWindowsEx(UINT uFlags,
        DWORD dwReserved)对于这个  有跟的参数决定是关机重启还是注销InitiateSystemShutdown(
        LPSTR lpMachineName,
        LPSTR lpMessage,
        DWORD dwTimeout,
        BOOL bForceAppsClosed,
        BOOL bRebootAfterShutdown
        )这个参数没详细研究 不知道有没有标注的
      

  4.   

    小弟我是搞java的,但java却没办法实现,
    还请各位能够具体点,真是急煞小弟我也.
    能有个例子最好,谢谢!
      

  5.   

    C++ 6.0    VC++ .NET   都可以实现 gina    gina 中有18个函数, 只要你舍得研究.  你那个要求, 只不过是一个小儿科,
      

  6.   

    寫一個windows服務,在啟動服務(開機)及停止服務(關機)進寫到win log中
      

  7.   

    Microsoft.Win32.SystemEvents.SessionSwitch 更改当前用户事件
    Microsoft.Win32.SystemEvents.SessionEnding 注销或关闭系统时的事件
      

  8.   

    win log是什么意思啊,?能否解释一下
      

  9.   

    完整示例:
    http://blog.csdn.net/ChengKing/archive/2005/12/24/561259.aspx
      

  10.   

    还有gina是什么东东,哪里可以找到它的文档?
      

  11.   

    有这样一个事件内容.就是在窗体关闭的时候你可以判断这个是用户关闭.还是系统关机或者重新启动的时候关闭.不过至于你说的那个开机登陆跟注销登陆就不知道如何去监视了,
      在WINDOW COLOSING事件去判断 
                if (e.CloseReason == CloseReason.windowsshutdown)
                    {
                        //你要做的事             
                    }
      

  12.   

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.InteropServices;namespace ShutDown
    {
        public class ExitWindows
        {
            [StructLayout(LayoutKind.Sequential, Pack = 1)]//公共语言运行库利用StructLayoutAttribute控制类或结构
            //的数据字段在托管内存中的物理布局,即类或结构需要按某种方式排列。
            //LayoutKind分为三种方式排列非托管内存:Auto、Explicit、Sequential
            //当选择用Sequential时需要用Pack规定大小。Pack的值为: 0, 1, 2, 4, 8, 16, 32, 64, 128
            internal struct TokPriv1Luid
            {
                public int Count;
                public long Luid;
                public int Attr;
            }
            [DllImport("kernel32.dll", ExactSpelling = true)]
            internal static extern IntPtr GetCurrentProcess();//得到当前进程的伪句柄。
            
            [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
            internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);//打开进程相联系的access token
            //access token (通道令牌?)是包含一个会话的安全信息        [DllImport("advapi32.dll", SetLastError = true)]
            internal static extern bool LookupPrivilegeValue(string host, string name, ref long pluid);//用于得到一个权限的本地唯一标识        [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
            internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,//赋予或解除一个access token的特权
                ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);        [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
            internal static extern bool ExitWindowsEx(int flg, int rea);//重启、注销、关闭计算机        internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
            internal const int TOKEN_QUERY = 0x00000008;
            internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
            internal const int TOKEN_ADJUST_DEFAULT = 0x0080;//以下TOKEN的值本例中没有用到
            internal const int TOKEN_ADJUST_GROUPS = 0x0040;
            internal const int TOKEN_ADJUST_SESSIONID = 0x0100;
            internal const int TOKEN_ASSIGN_PRIMARY = 0x0001;
            internal const int TOKEN_DUPLICATE = 0x0002;
            internal const long TOKEN_EXECUTE = 0x20000L;
            internal const int TOKEN_IMPERSONATE = 0x0004;
            internal const int TOKEN_QUERY_SOURCE = 0x0010;
            //internal const int TOKEN_READ=0x200e0L;
            internal const long TOKEN_WRITE = 0x200e0L;
            internal const long TOKEN_ALL_ACCESS = 0xf00ffL;
            internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
            internal const int EWX_LOGOFF = 0x00000000;
            internal const int EWX_SHUTDOWN = 0x00000001;
            internal const int EWX_REBOOT = 0x00000002;
            internal const int EWX_FORCE = 0x00000004;
            internal const int EWX_POWEROFF = 0x00000008;
            internal const int EWX_FORCEIFHUNG = 0x00000010;
            public ExitWindows()
            {
                //
                // TODO: 在此处添加构造函数逻辑
                //
            }
            public bool DoExitWindows(int how)//执行
            {
                bool ok;
                TokPriv1Luid tp;
                IntPtr hproc = GetCurrentProcess();//IntPtr是平台提供的一个结构体。它用于描述一个指针或句柄
                IntPtr htok = IntPtr.Zero;//IntPtr.Zero只读属性。用于初始化一个指针或句柄
                ok = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok);
                tp.Count = 1;
                tp.Luid = 0;
                tp.Attr = SE_PRIVILEGE_ENABLED;
                ok = LookupPrivilegeValue(null, SE_SHUTDOWN_NAME, ref tp.Luid);
                ok = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
                switch (how)
                {
                    case 0:
                        ok = ExitWindowsEx(EWX_LOGOFF, 0);
                        break;
                    case 1:
                        ok = ExitWindowsEx(EWX_SHUTDOWN, 0);
                        break;
                    case 2:
                        ok = ExitWindowsEx(EWX_REBOOT, 0);
                        break;
                    case 3:
                        ok = ExitWindowsEx(EWX_FORCE, 0);
                        break;
                    case 4:
                        ok = ExitWindowsEx(EWX_POWEROFF, 0);
                        break;
                    case 5:
                        ok = ExitWindowsEx(EWX_FORCEIFHUNG, 0);
                        break;
                }
                return ok;
            }    }
    }
      

  13.   

    const int WM_QUERYENDSESSION = 0x0011;
           protected override void WndProc(ref Message m)
            {
                switch (m.Msg)
                {                case WM_QUERYENDSESSION:
                        this.Close();
                        this.Dispose();
                        Application.Exit();                    //m.Result = (IntPtr)0;
                        break;
                    default:
                        break;
                }
                base.WndProc(ref m);
            }
    放在你的mainForm.cs里
    这个是截获重启和关机的例子
    结合上面一个我发的应该可以解决了.
      

  14.   

    http://blog.csdn.net/hwenycocodq520 哈哈,请关注我的博客,很快我就把你需要知道的写在上面~~
      

  15.   

    先开启策略审核
      单击 开始 , 然后单击 控制面板 。
      双击 管理工具 , 并双击 本地安全设置 。
      展开 本地策略 , 然后展开 审核策略 。
      在右窗格中, 双击 审核系统事件 。
      单击以选中 成功 复选框, 并单击 确定 。
    读取系统日志中的开机、关机、注销、登录事件。代码如下:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Text;using System.Diagnostics;public partial class Default3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
         {
            //Windows日志有:"Application"应用程序, "Security"安全, "System"系统
            string[] logs = new string[] { "Application", "System" };         StringBuilder result = new StringBuilder();        foreach (string log in logs)
             {
                 EventLog myLog = new EventLog();
                 myLog.Log = log;
                //myLog.MachineName = "rondi-agt0qf9op";
                foreach (EventLogEntry entry in myLog.Entries)
                 {
                    //EventLogEntryType枚举包括:
                    //Error 错误事件。
                    //FailureAudit 失败审核事件。
                    //Information 信息事件。
                    //SuccessAudit 成功审核事件。
                    //Warning 警告事件。
                    if (entry.EntryType == EventLogEntryType.Error || entry.EntryType == EventLogEntryType.Warning)
                     {
                         result.Append("<font color='red'>" + log);
                         result.Append(entry.EntryType.ToString() + "</font>");
                         result.Append("<font color='blue'>(" + entry.TimeWritten.ToString() + ")</font>:");
                         result.Append(entry.Message + "<br /><br />");
                     }
                 }
             }
             Response.Write(result.ToString());
         }
    }