[DllImport("user32.dll", EntryPoint="ExitWindowsEx")]
public static extern int ExitWindows (
int dwReserved,
int uReturnCode
);或者:[DllImport("user32.dll")]
public static extern int ExitWindowsEx (
int dwReserved,
int uReturnCode
);

解决方案 »

  1.   

    to  AhBian(阿扁) :
     我为何关不了机呀?应用什么参数?
      

  2.   

    uFlags 4 = Force any applications to quit instead of prompting the user to close them. 0 = Log off the network. 8 = Shut down the system and, if possible, turn the computer off. 2 = Perform a full reboot of the system. 1 = Shut down computer.dwReasonThis is the System Shutdown Reason Code. If your application will run in an enterprise environment, set this to the appropriate value found in MSDN or talk to your/customer's IT department - they may have custom codes defined. If you don't care about this just set this = 0Sample Code:
            class Class1
            {
                    [DllImport("user32.dll")]
                    static extern bool ExitWindowsEx(uint uFlags, uint dwReason);
                    [STAThread]
                    static void Main(string[] args)
                    {
                            ExitWindowsEx(0, 0); //this will cause the computer to logoff.
                            ExitWindowsEx(1, 0); //And this will shutdown your computer.
                    }
            }
      

  3.   

    我从未用过这个 API,
    关机可能与权限有关。
      

  4.   

    [DllImport("user32.dll")]
    private static extern int ExitWindows (int dwReserved, int uReturnCode);