当我尝试将进程信息写入控制台时,我得到 System.ArgumentException 和 System.ComponentModel.Win32Exception。这是什么原因造成的?我怎样才能停止拥有这些?
Process processListe = Process.GetProcesses();
for (int i = 0; i < processListe.Count(); i++)
{
try
{
string companyName = processListe[i].MainModule.FileVersionInfo.CompanyName;
string fileVersion = processListe[i].MainModule.FileVersionInfo.FileVersion;
Console.WriteLine(companyName + " " + fileVersion);
}
catch (Exception) { }
}
“string companyName = processListe[i].MainModule.FileVersionInfo.CompanyName;”中发生错误 线。
错误信息:
System.ArgumentException: Illegal characters in path.
at System.Security.Permissions.FileIOPermission.HasIllegalCharacters(String[] str)
at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath)
at System.IO.Path.GetFullPath(String path)
at System.Diagnostics.FileVersionInfo.GetFullPathWithAssert(String fileName)
at System.Diagnostics.FileVersionInfo.GetVersionInfo(String fileName)
at System.Diagnostics.ProcessModule.get_FileVersionInfo()
A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll
System.ComponentModel.Win32Exception (0x80004005): Unable to enumerate the process modules.
at System.Diagnostics.NtProcessManager.GetModuleInfos(Int32 processId, Boolean firstModuleOnly)
at System.Diagnostics.NtProcessManager.GetFirstModuleInfo(Int32 processId)
at System.Diagnostics.Process.get_MainModule()
最后,我对那些让我出错的过程进行了信息输出:
Exception: Illegal characters in path.
Proess Name: winlogon Company Name: Aestan Software Version: 1.6.1.33
Detail: System.ArgumentException: Illegal characters in path.
at System.Security.Permissions.FileIOPermission.HasIllegalCharacters(String[] str)
at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath)
at System.IO.Path.GetFullPath(String path)
at System.Diagnostics.FileVersionInfo.GetFullPathWithAssert(String fileName)
at System.Diagnostics.FileVersionInfo.GetVersionInfo(String fileName)
at System.Diagnostics.ProcessModule.get_FileVersionInfo()
Exception: Illegal characters in path.
Proess Name: csrss Company Name: Microsoft Corporation Version: 2009.0100.1600.01 ((KJ_RTM).100402-1540 )
Detail: System.ArgumentException: Illegal characters in path.
at System.Security.Permissions.FileIOPermission.HasIllegalCharacters(String[] str)
at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath)
at System.IO.Path.GetFullPath(String path)
at System.Diagnostics.FileVersionInfo.GetFullPathWithAssert(String fileName)
at System.Diagnostics.FileVersionInfo.GetVersionInfo(String fileName)
at System.Diagnostics.ProcessModule.get_FileVersionInfo()
Exception: Unable to enumerate the process modules.
Proess Name: System Company Name: BitTorrent, Inc. Version: 7.5.0.25682
Detail: System.ComponentModel.Win32Exception (0x80004005): Unable to enumerate the process modules.
at System.Diagnostics.NtProcessManager.GetModuleInfos(Int32 processId, Boolean firstModuleOnly)
at System.Diagnostics.NtProcessManager.GetFirstModuleInfo(Int32 processId)
at System.Diagnostics.Process.get_MainModule()
Exception: Access is denied
Proess Name: Cheat Engine Company Name: Version: 5.6.1.10
Detail: System.ComponentModel.Win32Exception (0x80004005): Access is denied
at System.Diagnostics.ProcessManager.OpenProcess(Int32 processId, Int32 access, Boolean throwIfExited)
at System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean throwIfExited)
at System.Diagnostics.Process.get_HasExited()