先上代码及实例
RegistryKey rsg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Macromedia\FlashPaper Printer\2\Installation\", false);
为什么返回值是NULL
为什么返回值是NULL
L
原因其实是在64位电脑上跑32位程序,以上代码读取为空值,32位电脑读注册表使用OpenSubKey是正确的
解决方法:
I will show you how to get connecting string stored in registry. The code which I will show in this blog will work both on 32 and 64 bit machines. Let's say your connectingstring key name is "MyAppConnectionStringKey" and stored at following path "SOFTWARE\MyApp\Settings" with following value "Initial Catalog=mydb;Server=MY-PC;User ID=sa;Password=test"
Goal:
To get the "MyAppConnectionStringKey" value via code.