本文介绍了Process.MainModule - > "访问被拒绝"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要处理这种不同,
IE浏览器。确定我有机会或没有。
时可以看到,如果你有机会到主模块或没有?
的foreach(在Process.GetProcesses进程p())
{
试
{
//这会引发错误的一些过程。
如果(p.MainModule.FileName.ToLower()的endsWith(EXENAME,StringComparison.CurrentCultureIgnoreCase))
{
//做一些东西
}
}
赶上(例外)
{
//接取否认
}
}
解决方案
如果这是Windows 7或Vista的发生与提升进程才可以使用取胜API没有得到直接获取进程的路径。拒绝访问错误
请参阅此链接:
的
I want to handle this differently,ie. determine if I have access or not.
Is it possible to see if you have access to the main module or not?
foreach (Process p in Process.GetProcesses())
{
try
{
//This throws error for some processes.
if (p.MainModule.FileName.ToLower().EndsWith(ExeName, StringComparison.CurrentCultureIgnoreCase))
{
//Do some stuff
}
}
catch (Exception)
{
//Acess denied
}
}
解决方案
If this is happening on Windows 7 or Vista with elevated processes only then you can get the process path directly by using win api without getting access denied error.
See this links:
Access denied while getting process path
How to Get Elevated Process Path in .Net
这篇关于Process.MainModule - > "访问被拒绝"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!