在2000系统中
    程序中有
    ExitWindowsEx(EWX_REBOOT,0);
    ExitWindowsEx(EWX_SHUTDOWN,0);
   编译正常(引用了ShellAPI),为什么没有效果,不能重启,关机。
    Enablewindow(getdesktopwindow,false);
    Enablewindow(getdesktopwindow,true); 有效
请问是为什么,是操作系统的问题吗,要做到这些功能要用什么方法
请赐教。

解决方案 »

  1.   

    Function MySystemShutdown():boolean;
    var
       hToken:THANDLE;
       tkp:TOKEN_PRIVILEGES;
       zero : DWORD;
    begin
       // Get a token for this process. 
     
       if  not(OpenProcessToken(GetCurrentProcess(), 
            TOKEN_ADJUST_PRIVILEGES and TOKEN_QUERY, hToken)) then
          result := FALSE ;
     
       // Get the LUID for the shutdown privilege. 
     
       //LookupPrivilegeValue(nil, SE_SHUTDOWN_NAME ,@tkp.Privileges[0].Luid);
       LookupPrivilegeValue(nil, 'SeSecurityPrivilege' ,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,nil, 0);
       AdjustTokenPrivileges( hToken, False, tkp, SizeOf( TTokenPrivileges ), nil, zero );   if (GetLastError() <> ERROR_SUCCESS) then
          result := FALSE;
     
       // Shut down the system and force all applications to close. 
       //EWX_POWEROFF,EWX_LOGOFF,EWX_SHUTDOWN
       if not(ExitWindowsEx(EWX_REBOOT and EWX_FORCE, 0)) then
          result := FALSE;   result := TRUE;
    end;