(10) SetDWordValue
爲指定鍵值名稱的鍵值設置鍵值類型爲REG_DWORD的鍵值數值。
uint32 SetDWORDValue(
[in] uint32 hDefKey = 2147483650,
[in] string sSubKeyName,
[in] string sValueName,
[in] uint32 uValue
);
例1:爲鍵值名稱爲DWordValue的鍵值賦予類型爲REG_DWORD的鍵值數值11(0x0000000b)。該鍵值屬於HKEY_LOCAL_MACHINE\SOFTWARE\MyCompany子鍵。本例中該值被設置爲一個十進制整數,但可以使用任何能被VBScript識別的其他類型的基數(如16進制數)。
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
sMethod = "SetDWordValue"
Set oRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
strComputer & "/root/default:StdRegProv")
Set oMethod = oRegistry.Methods_(sMethod)
Set oInParam = oMethod.inParameters.SpawnInstance_()
oInParam.hDefKey = HKEY_LOCAL_MACHINE
oInParam.sSubKeyName = "SOFTWARE\MyCompany"
oInParam.sValueName = "DWordValue"
oInParam.uValue = 11
Set oOutParam = oRegistry.ExecMethod_(sMethod, oInParam)
If (oOutParam.ReturnValue = 0) And (Err.Number = 0) Then
Wscript.Echo "DWord value added successfully"
Else
Wscript.Echo "An error occurred"
End If
例2:本例直接調用SetDWordValue。
Const HKEY_LOCAL_MACHINE = &H80000002
sComputer = "."
Set oRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
sComputer & "/root/default:StdRegProv")
hDefKey = HKEY_LOCAL_MACHINE
sSubKeyName = "SOFTWARE\MyCompany"
sValueName = "DWordValue"
uValue = 11
oOutParam = oRegistry.SetDWordValue(hDefKey, sSubKeyName, sValueName, uValue)
If (oOutParam = 0) And (Err.Number = 0) Then
Wscript.Echo "DWord value added successfully"
Else
Wscript.Echo "An error occurred"
End If
例3:相應的PS程序。
$HKEY_LOCAL_MACHINE = "&H80000002"
$computer = "."
$namespace = "root\default"
$oRegistry = get-wmiobject -list -namespace $namespace -ComputerName $computer | where-object { $_.name -eq "StdRegProv" }
$hDefKey = $HKEY_LOCAL_MACHINE
$sSubKeyName = "SOFTWARE\MyCompany"
$sValueName = "DWordValue"
$uValue = 11
$oOutParam = $oRegistry.SetDWordValue($hDefKey, $sSubKeyName, $sValueName, $uValue)
"Retrun Colde is : " + $oOutParam.ReturnValue
(11) SetExpandedStringValue
爲指定鍵值名稱的鍵值設置鍵值類型爲REG_EXPAND_SZ的鍵值數值
uint32 SetExpandedStringValue(
[in, optional] uint32 hDefKey = 2147483650,
[in] string sSubKeyName,
[in] string sValueName,
[in] string sValue
);
例1:爲鍵值名稱爲ExpandedStringValue的鍵值賦予類型爲REG_EXPAND_SZ的鍵值數據“%SystemRoot%\MyCompany”該鍵值屬於HKEY_LOCAL_MACHINE\SOFTWARE\MyCompany子鍵。
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
sMethod = "SetExpandedStringValue"
Set oRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
strComputer & "/root/default:StdRegProv")
Set oMethod = oRegistry.Methods_(sMethod)
Set oInParam = oMethod.inParameters.SpawnInstance_()
oInParam.hDefKey = HKEY_LOCAL_MACHINE
oInParam.sSubKeyName = "SOFTWARE\MyCompany"
oInParam.sValueName = "ExpandedStringValue"
oInParam.sValue = "%SystemRoot%\MyCompany"
Set oOutParam = oRegistry.ExecMethod_(sMethod, oInParam)
If (oOutParam.ReturnValue = 0) And (Err.Number = 0) Then
Wscript.Echo "Expanded String value added successfully"
Else
Wscript.Echo "An error occurred"
End If
例2:本例直接調用SetExpandedStringValue。
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
strComputer & "/root/default:StdRegProv")
hDefKey = HKEY_LOCAL_MACHINE
sSubKeyName = "SOFTWARE\MyCompany"
sValueName = "ExpandedStringValue"
sValue = "%SystemRoot%\MyCompany"
oOutParam = oRegistry.SetExpandedStringValue(hDefKey,sSubKeyName, _
sValueName,sValue)
WScript.Echo "The return code is : " & oOutParam
例3:相應的PS程序
$HKEY_LOCAL_MACHINE = "&H80000002"
$computer = "."
$namespace = "root\default"
$oRegistry = get-wmiobject -list -namespace $namespace -ComputerName $computer | where-object { $_.name -eq "StdRegProv" }
$hDefKey = $HKEY_LOCAL_MACHINE
$sSubKeyName = "SOFTWARE\MyCompany"
$sValueName = "ExpandedStringValue"
$sValue = "%SystemRoot%\MyCompany"
$oOutParam = $oRegistry.SetExpandedStringValue($hDefKey, $sSubKeyName, $sValueName, $sValue)
"Retrun Colde is : " + $oOutParam.ReturnValue
(12) SetMultiStringValue
爲指定鍵值名稱的鍵值設置鍵值類型爲REG_MULTI_SZ的鍵值數值,該數值是一個多個字符串的數組。注意,在Windows 2000上如果使用REGEDT32命令來查看,每個字符串將以單行顯示;如果使用REGEDIT來查看,將顯示一個連續的字符串。
uint32 SetMultiStringValue(
[in] uint32 hDefKey = 2147483650,
[in] string sSubKeyName,
[in] string sValueName,
[in] Variant sValue[]
);
例1:爲鍵值名稱爲MultiStringValue的鍵值賦予類型爲REG_MULTI_SZ的鍵值數據("www","swynk","com" ),該鍵值數據是一個由多個字符串組成的數組,該鍵值屬於HKEY_LOCAL_MACHINE\SOFTWARE\MyCompany子鍵。
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
sMethod = "SetMultiStringValue"
Set oRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
strComputer & "/root/default:StdRegProv")
Set oMethod = oRegistry.Methods_(sMethod)
Set oInParam = oMethod.inParameters.SpawnInstance_()
oInParam.hDefKey = HKEY_LOCAL_MACHINE
oInParam.sSubKeyName = "SOFTWARE\MyCompany"
oInParam.sValueName = "MultiStringValue"
oInParam.sValue = Array("www","swynk","com")
Set oOutParam = oRegistry.ExecMethod_(sMethod, oInParam)
If (oOutParam.ReturnValue = 0) And (Err.Number = 0) Then
Wscript.Echo "MultiString value added successfully"
Else
Wscript.Echo "An error occurred"
End If
例2:本例直接調用SetMultiStringValue。
Const HKEY_LOCAL_MACHINE = &H80000002
sComputer = "."
hDefKey = HKEY_LOCAL_MACHINE
sSubKeyName = "SOFTWARE\MyCompany"
sValueName = "MultiStringValue"
sValue = Array("www","swynk","com")
Set oRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
sComputer & "/root/default:StdRegProv")
oOutParam = oRegistry.SetMultiStringValue(hDefKey,sSubKeyName,sValueName,sValue)
WScript.Echo "The return code is : " & oOutParam
例3:相應的PS程序。
$HKEY_LOCAL_MACHINE = "&H80000002"
$computer = "."
$namespace = "root\default"
$oRegistry = get-wmiobject -list -namespace $namespace -ComputerName $computer | where-object { $_.name -eq "StdRegProv" }
$hDefKey = $HKEY_LOCAL_MACHINE
$sSubKeyName = "SOFTWARE\MyCompany"
$sValueName = "MultiStringValue"
$sValue = ("www","swynk","com")
$oOutParam = $oRegistry.SetMultiStringValue($hDefKey, $sSubKeyName, $sValueName, $sValue)
"Retrun Colde is : " + $oOutParam.ReturnValue