空注册表项读取Windows 10

时间:2019-05-21 20:36:58

标签: vb.net registry

尝试使用vb.net应用程序读取HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Office \ ClickToRun \ Configuration:ProductReleaselds的值,其中该应用程序已针对任何CPU编译。

(1)跟随失败的https://docs.microsoft.com/en-us/dotnet/visual-basic/developing-apps/programming/computer-resources/reading-from-and-writing-to-the-registry-using-the-microsoft-win32-namespace

(2)后跟https://docs.microsoft.com/en-us/dotnet/visual-basic/developing-apps/programming/computer-resources/how-to-read-a-value-from-a-registry-key,但同样失败。

我基于以上(1)的代码:

        Dim keyValue As String = "Software\\Microsoft\\Office\\ClickToRun\\Configuration"
        regVersion = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(keyValue, False)

        Dim MyAnswer As String = "initially blank"
        If regVersion IsNot Nothing Then
            MyAnswer= regVersion.GetValue("ProductReleaselds", Nothing)
            regVersion.Close()
        End If

我基于上述(2)的代码:

MyAnswer = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\ClickToRun\Configuration", 
    "ProductReleaselds", Nothing)

期望返回“ O36​​5BusinessRetail”,但没有骰子

1)使用断点,我看到regversion是Nothing,这意味着MyAnswer从不重新定义。

2)MyAnswer没事

尝试了几种变体,但均未成功。

发现了类似的问题(例如Cannot read value of Registry Key - VB.NET - HKLM),但没有有效的答案(37802919编译错误:“ RegistryKey.OpenBaseKey未定义”)。

0 个答案:

没有答案