从正在运行的进程VB.net获取“ALL”文件名和路径

时间:2015-07-16 10:57:01

标签: vb.net md5 filenames

IT; S VB.NET不是C#,我不知道如何将源代码从C#交换到VB.NET,谢谢

我想从所有正在运行的进程中获取所有路径 到目前为止,这是我的来源:

For Each p As Process In Process.GetProcesses
    Try
        ListBox1.Items.Add(p.MainModule.FileName.ToString)
    Catch ex As Exception
        RichTextBox1.Text = ex.Message
    End Try
Next

但我无法获取正在运行的进程的所有路径文件夹。

如果我检查ex.Message,响应就像这样

  

无法枚举过程模块。

但如果我不使用ex.Message,则响应如下:

System.ComponentModel.Win32Exception was unhandled

ErrorCode=-2147467259
  HResult=-2147467259
  Message=A 32 bit processes cannot access modules of a 64 bit process.
  NativeErrorCode=299
  Source=System
  StackTrace:
       at System.Diagnostics.NtProcessManager.GetModuleInfos(Int32 processId, Boolean firstModuleOnly)
       at System.Diagnostics.NtProcessManager.GetFirstModuleInfo(Int32 processId)
       at System.Diagnostics.Process.get_MainModule()
       at Anti_Cheat.Form1.Button6_Click(Object sender, EventArgs e) in c:\users\adiyatma\documents\visual studio 2012\Projects\Anti Cheat\Anti Cheat\Form1.vb:line 40
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at Anti_Cheat.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

任何人都可以帮助我吗?

2 个答案:

答案 0 :(得分:1)

看看问题How to get the full path of running process?

而不是

ListBox1.Items.Add(p.MainModule.FileName.ToString)

ListBox1.Items.Add(p.Modules(0).FileName.ToString)

编辑:

您是否尝试直接评估不同流程的属性?也许有一些您无法访问的过程,导致所描述的错误。

您可以尝试通过创建以下循环逐个迭代这些过程:

For Each p As System.Diagnostics.Process In System.Diagnostics.Process.GetProcesses()
    Try
        Console.WriteLine(p.Modules(0).FileName)
    Catch ex As Exception
        Console.WriteLine(String.Format("{0}: Error - {1}", p.ProcessName, ex.Message))
    End Try
Next

通过这样做,您应该能够确定您不允许访问的流程,并获得您应该可以尝试的几个流程。

答案 1 :(得分:0)

配合问题很明显,你的目标是32位,但是在安装了64位系统的计算机上测试你的应用程序,这就是你得到错误的原因。 消息= 32位进程无法访问64位进程的模块。

要修复这个问题,你应该把目标设为64位,这个没有解决方案...... 如果你知道着名的procexp(sysinternals)它有两个独立的应用程序,当系统是32位时,它会引发一个32位的实例,但是当它是64位时,它会为系统推出另一个独立的进程...... 所以如果你想处理这个问题,你必须为系统兼容性制作两个实例, 希望这有用