問題
使用 Process Call Dos To Get IP Address
解決方法
private string GetLookup() { string retval = ""; ProcessStartInfo psi = new ProcessStartInfo("cmd.exe", "/c ipconfig"); psi.UseShellExecute = false; psi.RedirectStandardOutput = true; psi.RedirectStandardInput = true; psi.RedirectStandardError = true; psi.CreateNoWindow = false; Process p = new Process(); p.StartInfo = psi; p.Start(); StreamReader se = p.StandardError; StreamReader so = p.StandardOutput; //retval += so.ReadToEnd(); //retval += se.ReadToEnd(); while (!so.EndOfStream) { String line = string.Empty; line = so.ReadLine(); if (line.IndexOf("IP Address") <>0) { int index = line.IndexOf(":"); index += 2; retval = line.Substring(index); } } /* while (!p.HasExited) { retval += so.ReadToEnd(); retval += se.ReadToEnd(); } retval += so.ReadToEnd(); retval += se.ReadToEnd(); */ p.Close(); p.Dispose(); return retval; }
沒有留言:
張貼留言