WIN98和WIN2000的关机有什么不同,WIN2000如何实现关机?

解决方案 »

  1.   

    使用ExitWindowsEx();这个函数
    msdn上在win2k下关机的一段例子
    HANDLE hToken; 
    TOKEN_PRIVILEGES tkp; 
     
    // Get a token for this process. 
     
    if (!OpenProcessToken(GetCurrentProcess(), 
            TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) 
        error("OpenProcessToken"); 
     
    // Get the LUID for the shutdown privilege. 
     
    LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, 
            &tkp.Privileges[0].Luid); 
     
    tkp.PrivilegeCount = 1;  // one privilege to set    
    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 
     
    // Get the shutdown privilege for this process. 
     
    AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, 
            (PTOKEN_PRIVILEGES)NULL, 0); 
     
    // Cannot test the return value of AdjustTokenPrivileges. 
     
    if (GetLastError() != ERROR_SUCCESS) 
        error("AdjustTokenPrivileges"); 
     
    // Shut down the system and force all applications to close. 
     
    if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) 
        error("ExitWindowsEx"); 
    这个函数win98也支持 但是传参数的时候一些宏定义的作用和在w2k下就不一样了
    具体可以看看msdn
    这段代码在win2k下没问题 win98就不知道了 没装 .
      

  2.   

    if (!OpenProcessToken(GetCurrentProcess(), 
            TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) 
        error("OpenProcessToken"); 
     
    // Get the LUID for the shutdown privilege. 
     
    LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, 
            &tkp.Privileges[0].Luid); 
     
    tkp.PrivilegeCount = 1;  // one privilege to set    
    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 
     
    // Get the shutdown privilege for this process. 
     
    AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, 
            (PTOKEN_PRIVILEGES)NULL, 0); 
     
    // Cannot test the return value of AdjustTokenPrivileges. 
     
    if (GetLastError() != ERROR_SUCCESS) 
        error("AdjustTokenPrivileges"); 
     
    // Shut down the system and force all applications to close. 我的MSDN怎么找不到这些呢?是不是我的MSDN不行,还是你说的不是真的
      

  3.   

    ExitWindowsEx();
    是吗?
    一个最简短的关机的程序怎么写?
      

  4.   

    OSVERSIONINFO osv;
    osv.dwOSVersionInfoSize=sizeof OSVERSIONINFO;
    GetVersionEx(&osv);if(osv.dwPlatformId==VER_PLATFORM_WIN32_NT)
    {
    HANDLE hProcess,hToken;
    TOKEN_PRIVILEGES Privileges;
    LUID luid;
    hProcess=GetCurrentProcess();
    OpenProcessToken(hProcess,TOKEN_ADJUST_PRIVILEGES,&hToken);
    Privileges.PrivilegeCount=1;
    LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&luid);
    Privileges.Privileges[0].Luid=luid;
    Privileges.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;
    AdjustTokenPrivileges(hToken,FALSE,&Privileges,NULL,NULL,NULL);
    }
    ExitWindowsEx(EWX_POWEROFF|EWX_SHUTDOWN|EWX_FORCE,0);
      

  5.   

    关机前当前进程要先获得一个关机权限
    你在msdn 2001或者2003中的Index中找ExitWindowsEx()这个函数 其中有一个连接就是我贴的那段代码