How to view the W3WP process by c#?
2011-11-17 23:32
441 查看
We need to know which w3wp process is running now When we debug my website in the Visual Studio. As we know, we can use this cmd(%windir%/system32/inetsrv/appcmd list wp) to show the result in the windows2008. But, How to view the W3WP process
by c#?
I give the method to you, please look this code:
Please take attention to the code: Process p = new Process();
we can use the Process object to run the cmd.exe process, and then run the "appcmd list wp" command. after it, we can receive the output string, and analyse the string to get the result of what we want to get.
by c#?
I give the method to you, please look this code:
static void Main(string[] args) { string str = CmdListWP(); Console.WriteLine(str); Console.WriteLine("Please press any key to exit!"); Console.ReadLine(); } private static string CmdListWP() { Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; //设定调用程序的名称 p.StartInfo.UseShellExecute = false; //关闭Shell的使用 p.StartInfo.RedirectStandardInput = true; //重定向标准输入 p.StartInfo.RedirectStandardOutput = true; //重定向标准输出 p.StartInfo.RedirectStandardError = true; //重定向错误输出 p.StartInfo.CreateNoWindow = true; //配置不显示窗口 string output; p.Start(); try { p.StandardInput.WriteLine("%windir%/system32/inetsrv/appcmd list wp"); p.StandardInput.WriteLine("exit"); output = p.StandardOutput.ReadToEnd(); } finally { p.Close(); } string result = string.Empty; if (output.IndexOf("WP \"") != -1) //是否有启动的站点 { //正则表达式提取 //for example: WP "29308" <applicationPool:profile3.csdn.net> string pattern = "WP \"\\d+\" .+"; List<string> list = new List<string>(); Regex regex = new Regex(pattern); if (regex.IsMatch(output)) { MatchCollection mc = regex.Matches(output); for (int i = 0; i < mc.Count; i++) { list.Add(mc[i].Value); } } foreach (string str in list) { result += str + "\n"; } } return result; }
Please take attention to the code: Process p = new Process();
we can use the Process object to run the cmd.exe process, and then run the "appcmd list wp" command. after it, we can receive the output string, and analyse the string to get the result of what we want to get.
相关文章推荐
- How to view the W3WP process by c#?
- How to view the W3WP process by c#?
- How to view the W3WP process by c#?
- How to populate the datagrid on background thread with data binding by using Visual C#
- How To Trace The Remote File Server (RFS) Process In Physical Standby Database (Doc ID 1481125.1)
- How to authenticate against the Active Directory by using Forms authentication and Visual C# .NET
- How to use C# code to get the windows components
- How To Read and Write BLOB Data by Using ADO.NET with Visual C# .NET
- How to hide the create button dynamical tree view in openerp ?
- virtual memory layout and how to get it by the correspoinding functuon
- In C# how to find the mime type of a file
- How to open the dialog out of iframe by using jquery dialog
- [Chapter 3 Process]Practice 3.9 Describe the actions token by a kernel to content-switch between processes.
- C# The process cannot access the file because it is being used by another process
- vim faq: how to view the hex text?
- How to Control the [Add document] button on the bottom of every view?
- XAF How to: Show a New Object Detail View via the Navigation Control
- Error:Unable to start the daemon process. This problem might be caused by incorrect configuration of
- USBView & How to get the Serial Number from a USB disk & qextserialport
- How to create new view by using cleartool command in Clearcase?