I'm trying to get a value from the registry in Windows, which sits under several branches:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\... 
Given the following code:
RegistryKey openSubKey = settings.OpenSubKey开发者_Python百科(
    @"\\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\DefaultSpoolDirectory");
openSubKey.SetValue("printername", "");
Where settings is set to LocalMachine in Microsoft.Win32.Registry.
However, I'd get null after the first line of code. What gives?
Two mistakes, \HKEY_LOCAL_MACHINE doesn't belong there, you should use Registry.LocalMachine instead. And DefaultSpoolDirectory doesn't belong there, it is a value, not a key.
The SetValue() arguments do not look happy either. If you want to add a printer (don't) then you'll need to add a key, not a value.
try removing "\hkey_local_machine"
Richard's answer seems correct, but just to inform you a little further, you can access the LocalMachine scope of the registry through the Registry.LocalMachine property - check this MSDN link for details. For an example, try this:
var openSubKey = Registry.LocalMachine.OpenSubKey(
    @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers");
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论