从 运行 进程 VB.net 获取 "ALL" 文件名和路径
Get "ALL" Filename and Path from a Running Process VB.net
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
,响应是这样的
Unable to enumerate the process modules.
但是如果我不使用 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:
谁能帮帮我?
看看正题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
通过这样做,您应该能够确定您不允许访问的进程并获得几个您应该能够试验的进程。
Mate 问题很明显,你的目标是 32 位,但在安装了 64 位系统的计算机上测试你的应用程序,这就是你得到错误的原因。
Message=32 位进程无法访问 64 位进程的模块。
要解决此问题,您应该将目标设置为 64 位,对此没有解决方案...
如果你知道著名的 procexp (sysinternals) 它有两个独立的应用程序,当系统是 32 位时它会启动一个 32 位的实例,但是当它是 64 位时它会为系统启动另一个单独的进程......
所以如果你想处理这个问题,你必须为系统兼容性制作两个实例,
希望这对您有所帮助
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
,响应是这样的
Unable to enumerate the process modules.
但是如果我不使用 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:
谁能帮帮我?
看看正题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
通过这样做,您应该能够确定您不允许访问的进程并获得几个您应该能够试验的进程。
Mate 问题很明显,你的目标是 32 位,但在安装了 64 位系统的计算机上测试你的应用程序,这就是你得到错误的原因。 Message=32 位进程无法访问 64 位进程的模块。
要解决此问题,您应该将目标设置为 64 位,对此没有解决方案... 如果你知道著名的 procexp (sysinternals) 它有两个独立的应用程序,当系统是 32 位时它会启动一个 32 位的实例,但是当它是 64 位时它会为系统启动另一个单独的进程...... 所以如果你想处理这个问题,你必须为系统兼容性制作两个实例, 希望这对您有所帮助