我正在尝试使用以下代码在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没有更改。如果在MessageBox.Show(My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon").GetValue("Shell"))
和winlogon.Close()
之间添加Return True
,则会得到一个显示正确值的消息框(这意味着该值已更改),但是当我检查regedit时,它会显示原始值,因此实际不更改值。
requireAdministrator
,然后重试,应该可以。如果删除异常处理Try Catch,则将了解确切原因。