zoukankan      html  css  js  c++  java
  • 实现注销 关机 重启计算机

    实现效果:  

      

    知识运用:

      方案1:

        ExitWindowsEx函数 //主要用来退出Windows操作系统   并用特定的选项重新启动 

        uFlags:要执行的操作  dwReserved:保留值 一般为0

        

      方案2:

        调用DOS命令  需使用Process类  (常用属性)

        

                         (常用方法)

        

     实现代码:

          
            [DllImport("user32.dll", EntryPoint = "ExitWindowsEx", CharSet = CharSet.Ansi)]
            private static extern int ExitWindowsEx(int uFlags,int dwReserved);
            private void button1_Click(object sender, EventArgs e)
            {
                ExitWindowsEx(0,0);     //注销
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
                myProcess.StartInfo.FileName = "cmd.exe";           //启动CMD命令
                myProcess.StartInfo.UseShellExecute = false;        //是否使用系统外壳程序启动进程
                myProcess.StartInfo.RedirectStandardOutput = true;  //是否写入流
                myProcess.StartInfo.RedirectStandardInput = true;   //是否从流中读取
                myProcess.StartInfo.RedirectStandardError = true;   //是否将错误信息写入流
                myProcess.StartInfo.CreateNoWindow = true;          //是否在新窗口中启动进程
                myProcess.Start();                                  //启动进程
                myProcess.StandardInput.WriteLine("shutdonw -s -t 0");  //执行关机命令
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
                myProcess.StartInfo.FileName = "cmd.exe";           //启动CMD命令
                myProcess.StartInfo.UseShellExecute = false;        //是否使用系统外壳程序启动进程
                myProcess.StartInfo.RedirectStandardOutput = true;  //是否写入流
                myProcess.StartInfo.RedirectStandardInput = true;   //是否从流中读取
                myProcess.StartInfo.RedirectStandardError = true;   //是否将错误信息写入流
                myProcess.StartInfo.CreateNoWindow = true;          //是否在新窗口中启动进程
                myProcess.Start();                                  //启动进程
                myProcess.StandardInput.WriteLine("shutdonw -r -t 0");  //执行重启命令
            }
    

      

  • 相关阅读:
    yii required 字段去除*号
    shtml用include加载文件,apache开启SSI,及shtml压缩
    门户站点用html或shtml文件格式的原因
    Apache配置shtml
    数据库迁移工具
    SQL SERVER2005 级联删除
    MySql级联删除和更新
    js只允许输入数字和小数点
    表格中的数据为空时,td的边框不显示
    MYSQL: Cannot delete or update a parent row: a foreign key constraint fails
  • 原文地址:https://www.cnblogs.com/feiyucha/p/10303098.html
Copyright © 2011-2022 走看看