1、读取注册表
Dim OperationRegistry
Set OperationRegistry=WScript.CreateObject("WScript.Shell")
Dim Read_Data1,Read_Data2,RegPath
RegPath="HKEY_CURRENT_USER\Software\7-Zip"
' 读取主键的键值,并将该数据送至变量Read_Data1
Read_Data1=OperationRegistry.RegRead(RegPath&"\Path")
MsgBox("Path="&Read_Data1)
Set OperationRegistry = Nothing
项名:计算机\HKEY_CURRENT_USER\Software\7-Zip
键名:Path
2、 写入注册表
Dim OperationRegistry
Set OperationRegistry=WScript.CreateObject("WScript.Shell")
Dim Read_Data1,Read_Data2,RegPath
RegPath="HKEY_CURRENT_USER\Software\7-Zip"
' 用管理者权限执行bat,调用vbs的方式才能写入这个目录的注册表里
OperationRegistry.RegWrite RegPath&"\test","helloworld"
Set OperationRegistry = Nothing
注意:有些需要注册表目录需要用管理者权限运行(管理者权限运行bat,bat调用vbs)才可以写入。
注意:执行vbs后,要刷新一下才能看到效果。
参考:vbscript Registry 注册表操作实现代码(读写删除)