C#关机代码Csharp判断是否链接网络
/// <summary>
/// 关机
/// </summary>
public static void ShutDownWindows(int second)
{
var startInfo = new ProcessStartInfo("cmd.exe");
startInfo.UseShellExecute = false;
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.CreateNoWindow = true;
var myProcess = new Process();
myProcess.StartInfo = startInfo;
myProcess.Start();
myProcess.StandardInput.WriteLine("shutdown -s -t " + second);
}
判断网络状态是否连接
/// <summary>
/// 是否连接网络
/// </summary>
/// <returns></returns>
public static bool NetworkIsLink()
{
Int32 flags = new int();
bool netWorkIsLink = InternetGetConnectedState(ref flags, 0);
return netWorkIsLink;
}