[DllImport("user32.dll", EntryPoint = "ExitWindowsEx", CharSet = CharSet.Ansi)]
 private static extern int ExitWindowsEx(int uFlags, int dwReserved);


 //注销计算机
        public void logout()
        {
            ExitWindowsEx(0, 0);  //调用API实现
        }
        //关闭计算机(通过CMD命令实现)
        public void closepc()
        {
            //创建访问控制本地系统进程的对象实例
            System.Diagnostics.Process myprocess = new System.Diagnostics.Process();
            myprocess.StartInfo.FileName = "cmd.exe";
            myprocess.StartInfo.UseShellExecute = false;
            myprocess.StartInfo.RedirectStandardInput = true;
            myprocess.StartInfo.RedirectStandardOutput = true;
            myprocess.StartInfo.RedirectStandardError = true;
            myprocess.StartInfo.CreateNoWindow = true;
            myprocess.Start();
            myprocess.StandardInput.WriteLine("shutdown -s -t 0");
        }
        //重新启动计算机(通过CMD命令实现)
        public void afreshstartpc()
        {
            //创建访问控制本地系统进程的对象实例
            System.Diagnostics.Process myprocess = new System.Diagnostics.Process();
            myprocess.StartInfo.FileName = "cmd.exe";
            myprocess.StartInfo.UseShellExecute = false;
            myprocess.StartInfo.RedirectStandardInput = true;
            myprocess.StartInfo.RedirectStandardOutput = true;
            myprocess.StartInfo.RedirectStandardError = true;
            myprocess.StartInfo.CreateNoWindow = true;
            myprocess.Start();
            myprocess.StandardInput.WriteLine("shutdown -r -t 0");
        }

相关文章:

  • 2022-12-23
  • 2021-05-30
  • 2021-10-30
  • 2021-10-19
  • 2021-07-01
  • 2021-09-27
  • 2022-03-04
猜你喜欢
  • 2022-02-28
  • 2021-06-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案