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>/// <returns></returns> 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; } /// <summary> /// Output the obtained information to the desktop/// </summary> static void InvokeCode() { string path = () + "\\" + ("yyyyMMddHHmmssfff") + ".txt"; (path, GetCode("ipconfig")); }
I hope this article will be helpful to everyone's C# programming.