2016-10-02 69 views
0

我需要從與其關聯的註冊表項(本例中爲「HKEY_LOCAL_MACHINE \ SOFTWARE \ Computers and Structures,Inc. \ SAP2000 \ 18 \ Install path」)讀取應用程序的安裝路徑。 。Visual Basic.net。嘗試讀取註冊表項不起作用

我曾嘗試以下:

ProgramPath = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Computers and Structures, Inc.\SAP2000\18", "Install path", Nothing) 

什麼也沒有結果。

也試過如下:

ProgramPath = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Computers and Structures, Inc.\\SAP2000\\18\\Install path", True) 

沒有成功要麼。

Here is how my registry looks like

我在做什麼錯? 在「Computers and Structures,Inc.」中是否可能存在空格或特殊字符(,。)的問題或在「安裝路徑」中?

對此的任何燈光將非常感激。提前致謝。

+0

http://stackoverflow.com/questions/9491958/registry-getvalue-always-return-null – Mino

回答

0

這對我的作品

Dim txt As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion", "ProductName", "") 

所以如果你的價值觀是正確的,請嘗試使用「」,而不是什麼

+0

感謝羅布,但它不適合我。結果仍然是「沒有」。 – darkjmf

+0

這裏有另一篇文章:http://stackoverflow.com/questions/9491958/registry-getvalue-always-return-null說:「如果它返回null,請將您的構建體系結構設置爲任何CPU。操作系統可以虛擬化32位和64位註冊表不同。「 - 可能有幫助? – Rob

1

尤里卡!

最終我發現,儘管我打算從註冊表的64位分支(「HKEY_LOCAL_MACHINE \ SOFTWARE \ Computers and Structures,Inc. \ SAP2000 \ 18」)中讀取,但我使用的所有說明確實正在訪問32位分支(「HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \ Computers and Structures,Inc. \ SAP2000 \ 18」),其中沒有「\ 18」子項,因此是錯誤。

一旦知道其中的錯誤是,這是很容易找到的https://stackoverflow.com/a/20910975/6912725

最終代碼的解決方案類似:

Dim regVersion64 As Microsoft.Win32.RegistryKey = Microsoft.Win32.RegistryKey.OpenBaseKey _ 
            (Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64). 
            OpenSubKey("SOFTWARE\Computers and Structures, Inc.\SAP2000\18") 
Dim ProgramPath As String = regVersion64.GetValue("Install path") 

謝謝大家的幫助,並希望這個線程可以幫助其他人。