我们的 VB6 遗留应用程序调用 RegSetValueEx 来设置注册表值。可以使用 regedit 轻松设置此注册表值。但是,当我们的应用程序尝试设置它时,RegSetValueEx 返回 5 - Access Is Denied。
我们使用相同的代码写入其他注册表项,一切正常。此外,用户是本地管理员。
密钥是使用 KEY_ALL_ACCESS 打开的,但我尝试使用(KEY_READ 或 KEY_WRITE),但也没有用。
Private Const READ_CONTROL = &H20000
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const KEY_CREATE_SUB_KEY = &H4
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_NOTIFY = &H10
Private Const SYNCHRONIZE = &H100000
Private Const STANDARD_RIGHTS_ALL = &H1F0000
Private Const STANDARD_RIGHTS_EXECUTE = (READ_CONTROL)
Private Const STANDARD_RIGHTS_READ = (READ_CONTROL)
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
Private Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
Private Const KEY_CREATE_LINK = &H20
Private Const KEY_ALL_ACCESS = &H3F
Private Const REG_OPTION_NON_VOLATILE = 0&
Private Const HKEY_LOCAL_MACHINE = &H80000002
Dim hKey As Long
Dim e As Long
Dim lCreate As Long
Dim tSA As SECURITY_ATTRIBUTES
Dim keyOpened As Boolean
e = RegCreateKeyEx(HKEY_LOCAL_MACHINE , "SOFTWARE\Classes\Word.Document.8", 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, tSA, hKey, lCreate)
e = RegSetValueExLong(hKey, "BrowerFlags", 0&, REG_DWORD, newValue, 4)