相关疑难解决方法(0)

在VBA中从/向注册表读取和写入

我在C#中看到了这一行,我正在尝试将其改编为VBA:

Microsoft.Win32.Registry.SetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR", "Start", 4,Microsoft.Win32.RegistryValueKind.DWord);
Run Code Online (Sandbox Code Playgroud)

我在这里迷失了一些错误:

运行时:5 - 程序调用无效)

当我使用默认的i_Type字符串"REG_SZ"而不是"Start"时,我得到一个与regkey相关的错误:

运行时 - -2147024891 [80070005]无效的根

我的代码:

Dim i_RegKey As String, i_Value As String, i_Type As String
Dim myWS As Object
i_Type = "REG_SZ"  ' Optional
'access Windows scripting
Set myWS = CreateObject("WScript.Shell")
'write registry key
i_RegKey = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR\Start"
i_Value = "4"
i_Type = "REG_DWORD"
myWS.RegWrite i_RegKey, i_Value, i_Type
Run Code Online (Sandbox Code Playgroud)

registry excel vba excel-vba registrykey

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

excel ×1

excel-vba ×1

registry ×1

registrykey ×1

vba ×1