gpt4 book ai didi

c# - 从 .NET 应用程序中重新启动 Windows

转载 作者:可可西里 更新时间:2023-11-01 03:03:30 26 4
gpt4 key购买 nike

如何使用 .NET 框架重新启动或关闭 Windows?

最佳答案

以下代码将从 shell 执行关机命令:

// using System.Diagnostics;

class Shutdown
{
/// <summary>
/// Windows restart
/// </summary>
public static void Restart()
{
StartShutDown("-f -r -t 5");
}

/// <summary>
/// Log off.
/// </summary>
public static void LogOff()
{
StartShutDown("-l");
}

/// <summary>
/// Shutting Down Windows
/// </summary>
public static void Shut()
{
StartShutDown("-f -s -t 5");
}

private static void StartShutDown(string param)
{
ProcessStartInfo proc = new ProcessStartInfo();
proc.FileName = "cmd";
proc.WindowStyle = ProcessWindowStyle.Hidden;
proc.Arguments = "/C shutdown " + param;
Process.Start(proc);
}
}

(来源:http://dotnet-snippets.de/dns/c-windows-herrunterfahren-ausloggen-neustarten-SID455.aspx

关于c# - 从 .NET 应用程序中重新启动 Windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/462381/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com