WMI monikers can consist of three parts: one mandatory component and two optional components. The mandatory component is the "winmgmts:" prefix.
All WMI monikers must begin with "winmgmts:" as shown here:
Set objSWbemServices = GetObject("winmgmts:")
After you have obtained a reference to SWbemServices, you can then invoke one of the object methods as shown here:
Set colSWbemObjectSet = objSWbemServices.InstancesOf("Win32_LogicalDisk")
Step 1、write the vb script as following, and save it as "NEW_RegistryKey.vbs"
HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
strSubKey = "SOFTWARE\MyKey\MySubKey"
strValueName = "MyValueName"
strValue = "MyValue"
'''''''1、Retrieve a locator object with a call to CreateObject
'''''''2、Log on to the namespace using a call to the ConnectServer method
'''''''3、Set the impersonation level with a call to the SWbemServices.Security_ method
Set ObjRegistry = _
GetObject("winmgmts:{impersonationLevel = impersonate}!\\" _
& strComputer & "\root\default:StdRegProv")
''''''4、Implement the purpose of your script,The StdRegProv class has CreateKey methods
Return = objRegistry.CreateKey(HKEY_LOCAL_MACHINE, strSubKey)
'''''''In scripting or Visual Basic, the method returns an integer value that is 0 (zero) if successful. If the function fails, the return value is a nonzero error
code that you can look up in WbemErrorEnum.
If Return <> 0 Then
WScript.Echo "The operation failed." & Err.Number
WScript.Quit
Else
wScript.Echo "New registry key created :" & VBCRLF _
& strSubKey
End If
objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strSubKey,strValueName ,strValue
Step 2、using cscript to run NEW_RegistryKey.vbs"on windows command prompt
Step 3、To check the result on registry setting
沒有留言:
張貼留言