C#关机代码Csharp判断是否连接网络

C#关机代码Csharp判断是否链接网络

/// 
  /// 关机
  /// 
  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);
  }

判断网络状态是否连接

/// 
  /// 是否连接网络
  /// 
  /// 
  public static bool NetworkIsLink()
  {
      Int32 flags = new int();
      bool netWorkIsLink = InternetGetConnectedState(ref flags, 0);    		 	
      return netWorkIsLink;
   }

你可能感兴趣的:(开发语言,c#,php,开发语言)