大伙都知道,点“开始”再点“关机”,就跳出了关机菜单,选择“重起动计算机”,然后在点“是”的同时按下键盘上的“Shift”键就可以实现【快速】重起动系统。小弟想知道的就是如何用ExitWindow或ExitWindowEx来实现上诉功能。另外,小弟还想问一下如何用ExitWindow或ExitWindowEx来实现
“重起动计算机器并切换到MS-DOS状态”。请各位大侠指教~ 感激不尽~

解决方案 »

  1.   

    大哥,95、98能到DOS,winme、2000、XP、2003也能吗?
      

  2.   

    program ExitNt; Uses
      Windows;
    {$R *.RES}function SetPrivilege(sPrivilegeName : string;bEnabled : boolean ): boolean;
    var
      TPPrev,
      TP : TTokenPrivileges;
      Token : THandle;
      dwRetLen : DWord;
    begin
      Result := False;
      //opens the access token associated with a process.
      OpenProcessToken(
      GetCurrentProcess, //handle to process
      TOKEN_ADJUST_PRIVILEGES //Required to change the privileges specified in an access token.
      or TOKEN_QUERY, //Required to query the contents of an access token.
      Token);
      TP.PrivilegeCount := 1;
      //retrieves the locally unique identifier (LUID) used on a specified system to
      //locally represent the specified privilege name.
      if( LookupPrivilegeValue(
      Nil, //attempts to find the privilege name on the local system.
      PChar( sPrivilegeName ), // address of string specifying the privilege
      TP.Privileges[ 0 ].LUID ) // address of locally unique identifier
      )then
      begin
        if( bEnabled )then //Give this privileges
        begin
          TP.Privileges[ 0 ].Attributes := SE_PRIVILEGE_ENABLED;
        end
        else
        begin //NOT Give this privileges
          TP.Privileges[ 0 ].Attributes := 0;
        end;
          dwRetLen := 0;
        //enables or disables privileges in the specified access token.
        Result := AdjustTokenPrivileges(
        Token, // handle to token that contains privileges
        False, //modifies privileges
        TP, // pointer to new privilege information
        SizeOf( TPPrev ), // size, in bytes, of the TPPrev buffer
        TPPrev, // receives original state of changed privileges
        dwRetLen // receives required size of the TPPrev buffer
        );
      end;
      CloseHandle(Token);
    end;
    function WinExitInNT( iFlags : integer ) : boolean;
    begin
      Result := True;
      if( SetPrivilege( 'SeShutdownPrivilege', True ) )then
      begin
        if( not ExitWindowsEx( iFlags, 0 ) )then
        begin
        Result := False;
        end;
      SetPrivilege( 'SeShutdownPrivilege', False )
      end
      else
      begin
    // handle errors...
      Result := False;
      end;
    end;
    begin
      WinExitInNT(EWX_SHUTDOWN+EWX_POWEROFF);
    end. 
      

  3.   

    在系统目录下找MSDOS的EXE文件,然后用CREATEPROCESS执行,并指定窗口模式.
    没试过,纯属个人,HOHOHO.
      

  4.   

    fengyvn
          谢谢你提供的方法,不过好象不是很好用!
    难道就没有其他方法了吗?win本身既然能实现,那么我们应该也可以实现啊?
      

  5.   

    在 win98 下有一个 bat 文件,点击后就可以进入倒 MS-DOS 模式下。 你可以找找看,看看这个bat 里面做了什么。 这个 bat 应该 在 system 目录中,或者 在 win98 目录中, 我也记不清了(好久没有使用win98了)。
      

  6.   

    WQmeng
       我找找看的,谢谢!
    不过我最想实现的还是 快速启动.
      

  7.   

    首先sendmessage(hwnd_broadcast,WM_CLOSE,0,0)
    再调用 bottom(底) 老兄的方法,
      

  8.   

    chw_csdn_chw(chw
       你的方法是不是给所有的程序发一个推出消息然后,再关闭系统啊?
    可是我要的不是关闭系统而是 快速重起动啊
      

  9.   

    procedure ExitWin2000(ewx: integer);//------退出windows
    var
      hToken: THANDLE;
      hProc: THANDLE;
      mLUID: TLargeInteger;
      mPriv, mNewPriv: TOKEN_PRIVILEGES;
      mBufferLength: DWord;
    begin
      if not (ewx in [1, 2]) then
        exit;
      hProc := GetCurrentProcess();
      OpenProcessToken(hProc, TOKEN_ADJUST_PRIVILEGES + TOKEN_QUERY, hToken);
      LookupPrivilegeValue('', 'SeShutdownPrivilege', mLUID);
      mPriv.PrivilegeCount := 1;
      mPriv.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
      mPriv.Privileges[0].Luid := mLUID;
      AdjustTokenPrivileges(hToken, False, mPriv, (4 + (12 * mPriv.PrivilegeCount)), mNewPriv, mBufferLength);
      case ewx of
        1: ExitWindowsEx(EWX_FORCE + EWX_REBOOT, 0);
        2: ExitWindowsEx(EWX_FORCE + EWX_POWEROFF, 0);
      end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      ExitWin2000(2);  //------1表示重启
    end;
      

  10.   

    dyxfkj(我爱我老婆)
      能够实现“快速”重启动吗?