自己动手,起码可以用进程获取路径吧,看到博问上“winform 获得已启动服务的启动参数 ”,呵呵,这两个貌似一种方法可以解决啊
WMI,还记得吗?
1
private
static
String GetResultByWql(String wql)
2 {
3 ManagementObjectSearcher mos = new ManagementObjectSearcher(wql);
4 foreach (ManagementObject mo in mos.Get())
5 {
6 PropertyDataEnumerator oEnum = (mo.Properties.GetEnumerator() as PropertyDataEnumerator);
7 while (oEnum.MoveNext())
8 {
9 PropertyData prop = (PropertyData)oEnum.Current;
10 if (prop.Value != null ) return prop.Value.ToString();
11 }
12 }
13 return null ;
14 }
2 {
3 ManagementObjectSearcher mos = new ManagementObjectSearcher(wql);
4 foreach (ManagementObject mo in mos.Get())
5 {
6 PropertyDataEnumerator oEnum = (mo.Properties.GetEnumerator() as PropertyDataEnumerator);
7 while (oEnum.MoveNext())
8 {
9 PropertyData prop = (PropertyData)oEnum.Current;
10 if (prop.Value != null ) return prop.Value.ToString();
11 }
12 }
13 return null ;
14 }
呵呵,WMI功能强大,基本你可以想得到的信息都可以囊括。
根据进程名称获取路径:
String strWql
=
String.Format(
"
SELECT ExecutablePath FROM Win32_Process where name ='{0}'
"
, textBoxProcessName.Text);
textBoxResult.Text = GetResultByWql(strWql);
textBoxResult.Text = GetResultByWql(strWql);
根据服务名称获取路径:
String strWql
=
String.Format(
"
SELECT PathName FROM Win32_Service where Name ='{0}'
"
,textBoxServiceName.Text);
textBoxResult.Text = GetResultByWql(strWql);
http://www.cnblogs.com/winzheng/archive/2009/07/31/1536167.html
textBoxResult.Text = GetResultByWql(strWql);
如此一个简单的方法和两个语句搞定两个功能,还不快体验一下啊
其实还有个问题我需要处理,我们经常遇到端口被占用的情况,究竟哪个端口被那个进程或服务占用了?
貌似WMI没有提供,需要用命令行获取,好了,等工具完善了发上来。
哪位有更好的办法,希望贡献出来,先谢了。
下班了,Let's go, 周末愉快。
态度决定一切,技术改变生活作者:winzheng
出处: http://cnblogs.com/winzheng
本文为原创作品,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。