C#实现控制Windows系统关机、重启和注销的方法

作者:令狐不聪 时间:2023-07-24 17:15:05 

本文实例讲述了C#实现控制Windows系统关机、重启和注销的方法。分享给大家供大家参考。具体分析如下:

使用.NET和C#.NET,我们可以对当前PC执行关机,重启,注销操作。

NET Framework中,有一个命名空间System.Diagnostics具有所需的类和方法,从当前PC上运行.NET应用程序来执行这些操作。
请使用下面的按钮来执行关机,重启和注销。

下面是一个winform程序


//SHUT DOWN
protected void btnShutDown_Click(object sender, EventArgs e)
{    
Process.Start("shutdown.exe", "-s");
// By Default the Shutdown will take place after 30 Seconds
//if you want to change the Delay try this one
Process.Start("shutdown.exe","-s -t xx");
//Replace xx with Seconds example 10,20 etc
}

//RESTART
protected void btnRestart_Click(object sender, EventArgs e)
{
Process.Start("shutdown.exe", "-r");
// By Default the Restart will take place after 30 Seconds
//if you want to change the Delay try this one
Process.Start("shutdown.exe","-r -t 10");
//Replace xx with Seconds example 10,20 etc
}

// LOG OFF
protected void btnLogOff_Click(object sender, EventArgs e)
{
Process.Start("shutdown.exe", "-l");
//This Code Will Directly Log Off the System Without warnings
}

希望本文所述对大家的C#程序设计有所帮助。

标签:C#,Windows,关机
0
投稿

猜你喜欢

  • Java中Request请求转发详解

    2021-05-25 20:53:42
  • Android实现倒计时的按钮的示例代码

    2021-10-17 14:45:11
  • maven中下载jar包源码和javadoc的命令介绍

    2023-07-27 04:41:01
  • 详解Spring Boot 定制HTTP消息转换器

    2023-11-24 20:20:51
  • Java多线程实现简易微信发红包的方法实例

    2023-04-16 11:46:15
  • Android开发input问题解决分析

    2021-11-10 08:58:46
  • LinkedBlockingQueue链式阻塞队列的使用和原理解析

    2022-11-01 22:37:30
  • springboot集成@DS注解实现数据源切换的方法示例

    2021-11-18 11:30:00
  • C#实现调用迅雷下载的方法

    2022-03-29 12:42:21
  • Java中equalsIgnoreCase()方法的使用

    2022-07-28 15:13:45
  • java中对List分段操作的实例

    2022-12-05 18:38:48
  • 登陆验证码kaptcha结合spring boot的用法详解

    2023-02-19 15:56:32
  • C++中的异常处理机制详解

    2023-04-16 16:01:10
  • Java mybatis 开发自定义插件

    2022-11-26 03:29:24
  • Android实现拼图游戏

    2023-06-29 20:48:25
  • Java DelayQueue实现任务延时示例讲解

    2023-03-17 01:37:49
  • Java BufferWriter写文件写不进去或缺失数据的解决

    2023-07-20 14:57:02
  • C#抽象类与抽象方法详解

    2022-05-20 18:08:03
  • C#使用Selenium的实现代码

    2021-11-16 05:58:25
  • Mybatis动态调用表名和字段名的解决方法

    2022-03-18 16:54:14
  • asp之家 软件编程 m.aspxhome.com