0
我正在嘗試創建一個應用程序,允許我輸入用戶名並通過修改HKEY_USERS \ UserSID下的註冊表來切換該用戶的默認打印機。儘管我似乎無法寫入註冊表的那部分值。也許這是Windows的限制?這是我迄今爲止的代碼。Writing from HKEY_USERS
Dim strComputer = "."
Dim objWMIService As Object = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Dim theUsername As String = TextBox1.Text
Dim theDomain As String = TextBox2.Text
Dim objAccount As Object = objWMIService.Get("Win32_UserAccount.Name='" & theUsername & "',Domain='" & theDomain & "'")
Dim theport As RegistryKey
theport = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion\\Devices")
Dim val As Object = theport.GetValue(ListBox1.SelectedItem)
theport.Close()
Dim theSid As String = objAccount.sid
Dim theKey As RegistryKey = Registry.Users.OpenSubKey(theSid + "\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows", True)
您有權利使用?你確定你在做什麼是一個好主意嗎?我不是。 – Wug
此外,用戶是否登錄?如果他們沒有登錄,那麼他們的註冊表配置單元將不會被加載。發生了什麼故障? – Luke
您的應用程序是否針對x86平臺編譯並在x64操作系統上運行? – Steve