System.ArgumentException和System.ComponentModel.Win32Exception时获取信息的过程 [英] System.ArgumentException and System.ComponentModel.Win32Exception when getting process information

查看:861
本文介绍了System.ArgumentException和System.ComponentModel.Win32Exception时获取信息的过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试写进程的信息来安慰我得到System.ArgumentException和System.ComponentModel.Win32Exception。是什么原因造成的? ?我怎么能阻止那些具有

 过程processListe = Process.GetProcesses(); 


的for(int i = 0; I< processListe.Count();我++)
{

{
串的companyName = processListe [I] .MainModule.FileVersionInfo.CompanyName;
串FILEVERSION = processListe [I] .MainModule.FileVersionInfo.FileVersion;

Console.WriteLine(的companyName ++文件版本);


}
赶上(例外){}


}

错误发生在字符串的companyName = processListe [I] .MainModule.FileVersionInfo.CompanyName; 。行



错误消息:

  System.ArgumentException:非法字符路径。 
在System.Security.Permissions.FileIOPermission.HasIllegalCharacters(字符串[] STR)在System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess访问,AccessControlActions控制
,的String [] pathListOrig,布尔checkForDuplicates,布尔needFullPath,布尔copyPathList)
在System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess访问的String [] pathList,布尔checkForDuplicates,布尔needFullPath)
在System.IO.Path.GetFullPath(字符串路径)
在System.Diagnostics.FileVersionInfo.GetFullPathWithAssert(字符串文件名)
在System.Diagnostics.FileVersionInfo.GetVersionInfo(字符串文件名)在System.Diagnostics.ProcessModule.get_FileVersionInfo
()


型System.ComponentModel.Win32Exception的第一次机会异常出现在System.dll中
System.ComponentModel.Win32Exception(0x80004005的):无法枚举进程的模块。
在System.Diagnostics.NtProcessManager.GetModuleInfos(的Int32进程ID,布尔firstModuleOnly)
在System.Diagnostics.NtProcessManager.GetFirstModuleInfo(的Int32进程ID)
在System.Diagnostics.Process.get_MainModule()

最后我做了这些过程,使我得到错误的信息输出:

 例外:路径中具有非法字符。 
流程处理名称:winlogon的公司名称:Aestan软件版本:1.6.1.33
详细信息:System.ArgumentException:路径中具有非法字符。
在System.Security.Permissions.FileIOPermission.HasIllegalCharacters(字符串[] STR)在System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess访问,AccessControlActions控制
,的String [] pathListOrig,布尔checkForDuplicates,布尔needFullPath,布尔copyPathList)
在System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess访问的String [] pathList,布尔checkForDuplicates,布尔needFullPath)
在System.IO.Path.GetFullPath(字符串路径)
在System.Diagnostics.FileVersionInfo.GetFullPathWithAssert(字符串文件名)
在System.Diagnostics.FileVersionInfo.GetVersionInfo(字符串文件名)在System.Diagnostics.ProcessModule.get_FileVersionInfo
()

例外:路径中具有非法字符。
流程处理名称:CSRSS公司名称:微软公司版本:2009.0100.1600.01((KJ_RTM).100402-1540)
详细信息:System.ArgumentException:路径中具有非法字符。
在System.Security.Permissions.FileIOPermission.HasIllegalCharacters(字符串[] STR)在System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess访问,AccessControlActions控制
,的String [] pathListOrig,布尔checkForDuplicates,布尔needFullPath,布尔copyPathList)
在System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess访问的String [] pathList,布尔checkForDuplicates,布尔needFullPath)
在System.IO.Path.GetFullPath(字符串路径)
在System.Diagnostics.FileVersionInfo.GetFullPathWithAssert(字符串文件名)
在System.Diagnostics.FileVersionInfo.GetVersionInfo(字符串文件名)在System.Diagnostics.ProcessModule.get_FileVersionInfo
()

例外:无法枚举进程的模块。
流程处理名称:系统公司名称:BitTorrent的公司版本:7.5.0.25682
详细信息:System.ComponentModel.Win32Exception(0x80004005的):无法枚举进程的模块。
在System.Diagnostics.NtProcessManager.GetModuleInfos(的Int32进程ID,布尔firstModuleOnly)
在System.Diagnostics.NtProcessManager.GetFirstModuleInfo(的Int32进程ID)
在System.Diagnostics.Process.get_MainModule()

异常:访问被拒绝
流程处理名称:作弊引擎公司名称:版本:5.6.1.10
详细信息:System.ComponentModel.Win32Exception(0x80004005的):访问被拒绝
。在System.Diagnostics.ProcessManager.OpenProcess(的Int32进程ID,访问的Int32,布尔throwIfExited)
在System.Diagnostics.Process.GetProcessHandle(的Int32访问,布尔throwIfExited)
在System.Diagnostics.Process.get_HasExited ()


解决方案

简短的回答是,你不能摆脱了异常。有几个例外的我看到,当我运行此代码,我没有看到明确的文档中叫了一声:




  1. Win32Exception - 拒绝访问:该进程正在运行作为用户和当前用户没有权限访问的过程。注意即使以管理员身份运行时,您将无法访问所有过程(因为DRM限制的例子audiodg.exe)

  2. Win32Exception - 一个32位进程无法访问一个64位的模块过程

  3. Win32Exception - 无法枚举进程模块 - 我看到这个发生在伪流程系统和空闲 - 它们不是真正的进程(它们是占位内核服务)和唐'T有任何模块列出。


When i try to write process' information to console i get System.ArgumentException and System.ComponentModel.Win32Exception. What causes this? How can i stop having those?

        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) { }


            }

Errors happen in "string companyName = processListe[i].MainModule.FileVersionInfo.CompanyName;" line.

Error messages:

   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()

Lastly i've made an information output of those process which makes me get errors:

    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()

解决方案

The short answer is that you can't get rid of the exceptions. There are a couple of exceptions I see when I run this code that I don't see explicitly called out in the documentation:

  1. Win32Exception - Access Denied: The process is running as a user and your current user doesn't have rights to access the process. Note even when running as administrator you won't have access to all processes (For example audiodg.exe because of DRM restrictions)
  2. Win32Exception - A 32 bit processes cannot access modules of a 64 bit process
  3. Win32Exception - Unable to enumerate the process modules - I see this occurring on the pseudo processes System and Idle - they aren't real processes (they are place holders for kernel services) and don't have any modules to list.

这篇关于System.ArgumentException和System.ComponentModel.Win32Exception时获取信息的过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆