简体   繁体   English

在 vb.net 中获取文件路径

[英]getting file path in vb.net

I'm using this code to get a list of current proccess.我正在使用此代码获取当前进程的列表。

For Each Proc As Process In ProcessList
Dim ProcessList As List(Of Process) = Process.GetProcesses.ToList
 Dim Name As String = Proc.ProcessName
 Dim Path As String = Proc.MainModule.FileName
Dim Icon As System.Drawing.Image = System.Drawing.Icon.ExtractAssociatedIcon(Path).ToBitmap
next

but I get an error on Dim Path As String = Proc.MainModule.FileName) which I think is because I'm using 64bit OS.但我在Dim Path As String = Proc.MainModule.FileName)上收到错误,我认为这是因为我使用的是 64 位操作系统。

Thanks in advance提前致谢

First of all you have ProcessList declared in your loop.首先,您在循环中声明了 ProcessList。 I assume that was a paste error.我认为这是一个粘贴错误。

The problem is that you can't access all the processes like that.问题是您无法像那样访问所有进程。 You will need to add a try catch.您将需要添加一个 try catch。

Dim ProcessList As List(Of Process) = Process.GetProcesses.ToList
For Each Proc As Process In ProcessList
    Dim Name As String = Proc.ProcessName
    Dim v = Environment.Is64BitProcess
    Try
        Dim Path As String = Proc.MainModule.FileName
        Dim Icon As System.Drawing.Image = System.Drawing.Icon.ExtractAssociatedIcon(Path).ToBitmap
    Catch ex As Exception
        Debug.WriteLine("Can't Access File Name: " + ex.Message + ", Process Name: " + Name)
    End Try
Next

See here for more details.有关更多详细信息,请参见此处。

How to avoid a Win32 exception when accessing Process.MainModule.FileName in C#? C#访问Process.MainModule.FileName时如何避免Win32异常?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM