//检查虚拟目录是否可以访问 public static bool Cmd(string cmdLine) { using (var process = new Process { StartInfo = { FileName = "cmd.exe", UseShellExecute = false, RedirectStandardInput = true, RedirectStandardOutput = true, CreateNoWindow = true, RedirectStandardError = true } }) { process.Start(); process.StandardInput.AutoFlush = true; process.StandardInput.WriteLine(cmdLine); process.StandardInput.WriteLine("exit"); Debug.WriteLine(process.StandardOutput.ReadToEnd()); String errorMessage = process.StandardError.ReadToEnd(); process.WaitForExit(); if (String.IsNullOrEmpty(errorMessage)) { return true; } Debug.WriteLine(errorMessage); return false; } }
//检查链接是否可以访问 public static bool CheckUrlVisit(string url) { try { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); if (resp.StatusCode == HttpStatusCode.OK) { resp.Close(); return true; } } catch (WebException webex) { return false; } return false; }