SoFunction
Updated on 2025-03-06

C# method to call the dos window to get related information

This article describes the method of C# calling the dos window to obtain relevant information. Share it for your reference. The specific implementation method is as follows:

/// <summary>
/// Call the dos window to get relevant information/// </summary>
/// <param name="cmd">such as:netstat-ano or ipconfig</param>/// &lt;returns&gt;&lt;/returns&gt;
static string GetCode(string cmd)
{
  ProcessStartInfo startInfo = new ProcessStartInfo("");
   = false;
   = true;//The window is not displayed  Process process = new Process();
   = startInfo;
   = true;
   = true;
  ();
  (cmd);
  ("exit");
  string netMessage = ();
  ();
  ();
  return netMessage;
}
/// &lt;summary&gt;
/// Output the obtained information to the desktop/// &lt;/summary&gt;
static void InvokeCode()
{
  string path = () + "\\" + ("yyyyMMddHHmmssfff") + ".txt";
  (path, GetCode("ipconfig"));
}

I hope this article will be helpful to everyone's C# programming.