VBS脚本使用WMI操作注册表的代码第1/2页

时间:2021-05-22

oReg.CreateKeyHKEY_LOCAL_MACHINE,strKeyPath

oReg.SetExpandedStringValueHKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
oReg.SetStringValueHKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
oReg.SetDWORDValueHKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
oReg.SetBinaryValueHKEY_LOCAL_MACHINE,strPath,strValueName,uBinary
oReg.SetMultiStringValueHKEY_LOCAL_MACHINE,strKeyPath,strValueName,arrStringValues

oReg.DeleteKeyHKEY_LOCAL_MACHINE,strKeyPath
oReg.DeleteValueHKEY_LOCAL_MACHINE,strKeyPath,strStringValueName

oReg.GetExpandedStringValueHKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
oReg.GetDWORDValueHKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
oReg.GetStringValueHKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
oReg.GetBinaryValueHKEY_LOCAL_MACHINE,strKeyPath,strValueName,uBinary
oReg.GetMultiStringValueHKEY_LOCAL_MACHINE,strKeyPath,strValueName,arrStringValues

'-------------------------------------------------------------------------------------------

ConstHKEY_CLASSES_ROOT=&H80000000
ConstHKEY_CURRENT_USER=&H80000001
ConstHKEY_LOCAL_MACHINE=&H80000002
ConstHKEY_USERS=&H80000003
ConstHKEY_CURRENT_CONFIG=&H80000005

'创建注册表项
constHKEY_LOCAL_MACHINE=&H80000002
strComputer="."
SetStdOut=WScript.StdOut
SetoReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
strComputer&"\root\default:StdRegProv")
strKeyPath="SOFTWARE\SystemAdminScriptingGuide"
oReg.CreateKeyHKEY_LOCAL_MACHINE,strKeyPath

'创建多字符串值
constHKEY_LOCAL_MACHINE=&H80000002
strComputer="."
SetoReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
strComputer&"\root\default:StdRegProv")
strKeyPath="SOFTWARE\SystemAdminScriptingGuide"
strValueName="MultiStringValueName"
arrStringValues=Array("firststring","secondstring",_
"thirdstring","fourthstring")
oReg.SetMultiStringValueHKEY_LOCAL_MACHINE,strKeyPath,_
strValueName,arrStringValues


'创建扩展的字符串值
constHKEY_LOCAL_MACHINE=&H80000002
strComputer="."
SetoReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
strComputer&"\root\default:StdRegProv")
strKeyPath="SOFTWARE\SystemAdminScriptingGuide"
strValueName="ExpandedStringValueName"
strValue="%PATHEXT%"
oReg.SetExpandedStringValueHKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

'创建字符串和DWORD值
constHKEY_LOCAL_MACHINE=&H80000002
strComputer="."
SetStdOut=WScript.StdOut
SetoReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
strComputer&"\root\default:StdRegProv")
strKeyPath="SOFTWARE\SystemAdminScriptingGuide"
strValueName="StringValueName"
strValue="stringvalue"
oReg.SetStringValueHKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
strValueName="DWORDValueName"
dwValue=82
oReg.SetDWORDValueHKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue



'删除注册表项

constHKEY_LOCAL_MACHINE=&H80000002
strComputer="."
SetoReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
strComputer&"\root\default:StdRegProv")
strKeyPath="SOFTWARE\SystemAdminScriptingGuide"
oReg.DeleteKeyHKEY_LOCAL_MACHINE,strKeyPath


'删除注册表值

constHKEY_LOCAL_MACHINE=&H80000002
strComputer="."
SetoReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
strComputer&"\root\default:StdRegProv")
strKeyPath="SOFTWARE\SystemAdminScriptingGuide"
strDWORDValueName="DWORDValueName"
strExpandedStringValueName="ExpandedStringValueName"
strMultiStringValueName="MultiStringValueName"
strStringValueName="StringValueName"
oReg.DeleteValueHKEY_LOCAL_MACHINE,strKeyPath,strDWORDValueName
oReg.DeleteValueHKEY_LOCAL_MACHINE,strKeyPath,strExpandedStringValueName
oReg.DeleteValueHKEY_LOCAL_MACHINE,strKeyPath,strMultiStringValueName
oReg.DeleteValueHKEY_LOCAL_MACHINE,strKeyPath,strStringValueName


'枚举注册表值和类型
'枚举子项
'列出注册表文件
'监视注册表子项事件
'监视注册表子树事件
'读取二进制注册表值

constHKEY_LOCAL_MACHINE=&H80000002
strComputer="."
SetStdOut=WScript.StdOut
SetoReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
strComputer&"\root\default:StdRegProv")
strKeyPath="SOFTWARE\Microsoft\WindowsNT\CurrentVersion"
strValueName="LicenseInfo"
oReg.GetBinaryValueHKEY_LOCAL_MACHINE,strKeyPath,_
strValueName,strValue
Fori=lBound(strValue)touBound(strValue)
StdOut.WriteLinestrValue(i)
Next
12下一页阅读全文

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章