[英]Unable to change registry on Windows 10
我正在嘗試使用以下代碼更改 Windows 10 上的 Shell 注冊表項的值:
Public Function overwriteStartup()
Try
Dim winlogon As RegistryKey = My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", True)
winlogon.SetValue("AutoRestartShell", 0, RegistryValueKind.DWord)
winlogon.SetValue("Shell", Application.ExecutablePath, RegistryValueKind.String)
winlogon.Flush()
winlogon.Close()
Return True
Catch ex As Exception
Return False
End Try
End Function
問題是 Shell 和 AutoRestartShell 沒有改變。 如果我在winlogon.Close()
和Return True
之間添加MessageBox.Show(My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon").GetValue("Shell"))
,我得到顯示正確值的消息框(這意味着值已更改),但是當我檢查 regedit 時,它顯示的是原始值,因此它實際上並沒有更改值。
如果您的應用可以讀取注冊表值 - 您必須先提供管理權限,然后才能讓您的應用寫入注冊表值。 Go 到應用程序清單並將權限設置為requireAdministrator
然后再試一次,它應該可以工作。
如果你去掉異常處理 Try Catch,你就會知道確切的原因。
我將目標框架更改為 .NET 4 並將目標 CPU 設置為 AnyCPU,它現在可以工作了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.