如题

解决方案 »

  1.   

    BOOL InitiateSystemShutdown(    LPTSTR lpMachineName, // address of name of computer to shut down  
        LPTSTR lpMessage, // address of message to display in dialog box 
        DWORD dwTimeout, // time to display dialog box 
        BOOL bForceAppsClosed, // force applications with unsaved changes flag 
        BOOL bRebootAfterShutdown  // reboot flag 
       );一段使用InitiateSystemShutdown关机的程序如下
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Buttons, TeEngine, Series, ExtCtrls, TeeProcs, Chart;type
      TForm1 = class(TForm)
        BitBtn1: TBitBtn;
        BitBtn2: TBitBtn;
        BitBtn3: TBitBtn;
        Button1: TButton;
        procedure BitBtn3Click(Sender: TObject);
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementationuses TeCanvas;{$R *.dfm}procedure TForm1.BitBtn3Click(Sender: TObject);
    var
    rl:Cardinal;
    hToken:Cardinal;
    tkp:TOKEN_PRIVILEGES;
    begin
    {获得用户关机特权,仅对Windows NT/2000/XP}
        OpenProcessToken(GetCurrentProcess,TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,hToken);
        if LookupPrivilegeValue(nil,'SeShutdownPrivilege',tkp.Privileges[0].Luid) then
        begin
          tkp.Privileges[0].Attributes:=SE_PRIVILEGE_ENABLED;
          tkp.PrivilegeCount:=1;
          AdjustTokenPrivileges(hToken,False,tkp,0,nil,rl);
        end;
        InitiateSystemShutdown(nil, //要关闭的计算机,如果是本机可以为空
        PChar('系统即将关闭'), //显示的信息
        20000, //延时时间
        true,   //是否强制结束
        false)  // 关机还是注销
        
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
    //关机延时界面弹出后,可以通过点击此按钮来取消关机
    AbortSystemShutdown(nil);
    end;end.
    D7+WINXP测试通过。
      

  2.   

    已知InitiateSystemShutdown可以完成shutdown和reboot,想知道能否完成poweroff。这样只是实现了shutdown,而没有实现poweroff。在一些机算机上,执行后,系统提示:可以安全地关闭计算机了,需要人工按机箱上的power键关机。而同样在这台机算机上,用ExitWindowsEx可以完成shutdown和poweroff。如果是ExitWindowsEx的shutdown,则与InitiateSystemShutdown的shutdown一样,需人工关电源。但ExitWindowsEx的poweroff可以实现关机且关电源,不需要人工关电源。
    我的问题是用InitiateSystemShutdown如何完成poweroff。
      

  3.   

    跟电源有关的,AT电源就必须手工按Powser键关机,ATX就不必。
      

  4.   

    现在都是atx电源了吧,那还有什么AT电源,那是N年前的事情了.
      

  5.   

    是同一台电脑,且肯定是ATX的。ExitWindowsEx可以poweroff,InitiateSystemShutdown只能shutdown和reboot,无法poweroff。查了API的头文件,只有SeShutdownPrivilege,没有SePowerOffPrivilege,是否InitiateSystemShutdown只能实现shutdown,不能实现poweroff?