ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "C:\\Windows\\System32\\wbem\\WMIC.exe";
startInfo.Arguments = "PATH Win32_SerialPort GET /VALUE";
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
Process processTemp = new Process();
processTemp.StartInfo = startInfo;
processTemp.EnableRaisingEvents = true;
processTemp.Start();
string output = processTemp.StandardOutput.ReadToEnd();
int indexOfBGEntry = output.IndexOf(""); //input filter keywords
if (indexOfBGEntry > -1)
{
string output_sub = output.Substring(indexOfBGEntry);
string str = "DeviceID=";
int i = output_sub.IndexOf(str);
int start = i + str.Length;
string substr = output_sub.Substring(start);
int end = substr.IndexOf("\r");
return output_sub.Substring(start, end);
}
return null;