1

我在这里遇到了一个非常愚蠢的文件重定向问题,似乎找不到解决方案。我在 VB.net 2010 中编写了一个程序。我将其设置为使用 .net Framework 4 和 anyCPU 进行编译。我正在使用 32 位视图枚举 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run 键,然后检查路径是否存在。在我达到 REG_EXPAND_SZ 值之前,一切都很好。例如,如果我在以下路径中使用 file.exists:%programfiles%\Hewlett-Packard\HP Remote Solution\HP_Remote_Solution.exe,它会说找不到文件。当我看到路径扩展为什么时,我看到它是 c:\Program Files\Hewlett-Packard\HP Remote Solution\HP_Remote_Solution.exe,即使它实际上位于 Program Files (x86) 目录中。所以问题是我如何让 %ProgramFiles% 显示 x86 目录,而不是 64 位目录?这是我的一些代码。

        If Environment.Is64BitOperatingSystem = True Then
        '64-BIT OS, HKLM, 32-BIT KEY
        Dim fileName
        Dim rbkey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)
        Dim rkey = rbkey.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
        If Not rkey Is Nothing Then
            For Each s As String In rkey.GetValueNames
                If s <> "" Then
                    fileName = parsePath(rkey.GetValue(s)) 'parsePath will parse out the swithes
                    If File.Exists(fileName) Then
                        MsgBox(fileName & " exists")
                    Else
                        MsgBox(fileName & " not exists")
                    End If
                End If
            Next
        End If
    End If
4

0 回答 0