#209293 - 2014-07-29 03:31 PM
Can functions have an OUT parameter
|
Bonji
Starting to like KiXtart
Registered: 2001-09-28
Posts: 169
Loc: Virginia
|
In all the years I've used KiXtart, I don't think I've ever tried to use an OUT parameter for a function. All function parameters I've ever defined are IN parameters. Does KiXtart not support this?
I'm trying to manipulate the registry using WMI because the KiXtart method will not work against the remote computer. However, all the WMI registry GETs put the data in the last parameter (variable) specified in the function, and I cannot get this to work no matter what I try.
Here's an example:
$oWMIReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\COMP1\root\default:StdRegProv")
$HKLM = 2147483650
$RegKey = "System\CurrentControlSet\Services\TCPIP\Performance"
$RegValue = "Open"
$Result = $oWMIReg.GetStringValue($HKLM, $RegKey, $RegValue, $OUTValue)
$ = MessageBox($OUTValue, "GetStringValue")
In theory (and in vbscript) the registry value will be in the variable $OUTValue.
|
|
Top
|
|
|
|
#209294 - 2014-07-29 03:43 PM
Re: Can functions have an OUT parameter
[Re: Bonji]
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4563
Loc: USA
|
This won't work?
$RegKey = "\\" + $Computername + "\HKLM\System\CurrentControlSet\Services\TCPIP\Performance"
$RegValue = "Open"
$result=readvalue($regkey,$regvalue)
|
|
Top
|
|
|
|
#209298 - 2014-07-29 05:21 PM
Re: Can functions have an OUT parameter
[Re: Allen]
|
Bonji
Starting to like KiXtart
Registered: 2001-09-28
Posts: 169
Loc: Virginia
|
It's not a pure solution, but it keeps everything inside my KiX script and most importantly: IT WORKS!!
That's a handy object to keep in mind for future needs. Thanks!
$VBScriptCode = '
Dim strData
Sub MySub()
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "' + $txtComp.Text + '"
strRegPath = "System\CurrentControlSet\Services\TCPIP\Linkage"
strRegVal = "Bind"
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
Return = oReg.GetMultiStringValue(HKEY_LOCAL_MACHINE,strRegPath,strRegVal,arrValues)
If (Return = 0) And (Err.Number = 0) Then
For Each strValue In arrValues
strData = strData & "{}{}" & strValue & vbCrLf
Next
Else
End If
End Sub'
$VBScript = CreateObject("ScriptControl")
$VBScript.Language = "VBScript"
$VBScript.AddCode($VBScriptCode)
$ = $VBScript.Run("MySub")
$aryReg = Split($VBScript.CodeObject.strData, "{}{}")
For Each $Element In $aryReg
$ = messagebox($Element, "Element")
Next
|
|
Top
|
|
|
|
#209305 - 2014-07-29 11:21 PM
Re: Can functions have an OUT parameter
[Re: Lonkero]
|
ChristopheM
Hey THIS is FUN
   
Registered: 2002-05-13
Posts: 311
Loc: STRASBOURG, France
|
hello,
WMI gives a solution to get "out" value. This is not very easy but it is possible. Here is an example of code "full KiXtart" :break on
$=SetOption( "Explicit", "ON" )
$=SetOption( "NoVarsInStrings", "ON" )
$=SetOption( "NoMacrosInStrings", "ON" )
global $namespace, $objWMIService, $objRegistry, $wmiclass, $wmimethod
global $objInParams, $objOutParams
global $HKEY_CLASSES_ROOT, $HKEY_CURRENT_USER, $HKEY_LOCAL_MACHINE
global $HKEY_USERS, $HKEY_CURRENT_CONFIG
$HKEY_CLASSES_ROOT = (CDBL(2147483647)+1) ; &80000000
$HKEY_CURRENT_USER = (CDBL(2147483647)+2) ; &80000001
$HKEY_LOCAL_MACHINE = (CDBL(2147483647)+3) ; &80000002
$HKEY_USERS = (CDBL(2147483647)+4) ; &80000003
$HKEY_CURRENT_CONFIG = (CDBL(2147483647)+6) ; &80000005
global $strComputer, $strRegKey, $strRegValueName, $RegValue, $byte
$strComputer = "."
$strRegKey = "System\CurrentControlSet\Services\TCPIP\Performance"
;-- Connect to WMI --
$namespace = "root\default"
$objWMIService = GetObject('winmgmts:{impersonationLevel=impersonate,(debug,security)}!\\'+$strComputer+'\'+$namespace)
$wmiclass = "StdRegProv"
$objRegistry = $objWMIService.Get($wmiclass)
;-------------------------------------------------------------------------------
; example to read a value in the registry with WMI with GetStringValue method
;
; uint32 GetStringValue(
; [in] uint32 hDefKey = HKEY_LOCAL_MACHINE,
; [in] string sSubKeyName,
; [in] string sValueName,
; [out] string sValue
; )
;-------------------------------------------------------------------------------
"First read (REG_SZ)" ?
$strRegValueName = "Open"
$wmimethod = "GetStringValue"
$objInParams = $objRegistry.Methods_($wmimethod).InParameters.SpawnInstance_
$objInParams.hDefKey = $HKEY_LOCAL_MACHINE
$objInParams.sSubKeyName = $strRegKey
$objInParams.sValueName = $strRegValueName
;-- Execute the GetStringValue method to read value in the registry --
$objOutParams = $objWMIService.ExecMethod( $wmiclass, $wmimethod, $objInParams )
;-- get the sValue parameter that is returned by GetStringValue method --
$RegValue = $objOutParams.sValue
". SubKeyName : " $objInParams.sSubKeyName ?
". ValueName : " $objInParams.sValueName ?
". value : " $RegValue ?
?
;-------------------------------------------------------------------------------
; example to read a value in the registry with WMI with GetDwordValue method
;
; uint32 GetDwordValue(
; [in] uint32 hDefKey = HKEY_LOCAL_MACHINE,
; [in] string sSubKeyName,
; [in] string sValueName,
; [out] uint32 uValue
; )
;-------------------------------------------------------------------------------
"Second read (REG_DWORD)" ?
$strRegValueName = "WbemAdapStatus"
$wmimethod = "GetDwordValue"
$objInParams = $objRegistry.Methods_($wmimethod).InParameters.SpawnInstance_
$objInParams.hDefKey = $HKEY_LOCAL_MACHINE
$objInParams.sSubKeyName = $strRegKey
$objInParams.sValueName = $strRegValueName
;-- Execute the GetDwordValue method to read value in the registry --
$objOutParams = $objWMIService.ExecMethod( $wmiclass, $wmimethod, $objInParams )
;-- get the uValue parameter that is returned by GetDwordValue method --
$RegValue = $objOutParams.uValue
". SubKeyName : " $objInParams.sSubKeyName ?
". ValueName : " $objInParams.sValueName ?
". value : " $RegValue ?
?
;-------------------------------------------------------------------------------
; example to read a value in the registry with WMI with GetBinaryValue method
;
; uint32 GetBinaryValue(
; [in] uint32 hDefKey = HKEY_LOCAL_MACHINE,
; [in] string sSubKeyName,
; [in] string sValueName,
; [out] uint8 uValue[]
; )
;-------------------------------------------------------------------------------
"Third read (REG_BINARY)" ?
$strRegValueName = "WbemAdapFileSignature"
$wmimethod = "GetBinaryValue"
$objInParams = $objRegistry.Methods_($wmimethod).InParameters.SpawnInstance_
$objInParams.hDefKey = $HKEY_LOCAL_MACHINE
$objInParams.sSubKeyName = $strRegKey
$objInParams.sValueName = $strRegValueName
;-- Execute the GetDwordValue method to read value in the registry --
$objOutParams = $objWMIService.ExecMethod( $wmiclass, $wmimethod, $objInParams )
;-- get the uValue parameter that is returned by GetDwordValue method --
$RegValue = $objOutParams.uValue
". SubKeyName : " $objInParams.sSubKeyName ?
". ValueName : " $objInParams.sValueName ?
". value : "
for each $byte in $regvalue
DecToHex($byte) " "
next
?
In this code, i read locally because $strComputer = "." To test remotely, just change the line $strComputer = "<remote computername>"
For more information, look at Microsoft MSDN Web Site (WMI StdRegProv)and see all methods GetXxxValue.
_________________________
Christophe
|
|
Top
|
|
|
|
#209307 - 2014-07-30 09:15 AM
Re: Can functions have an OUT parameter
[Re: Allen]
|
ChristopheM
Hey THIS is FUN
   
Registered: 2002-05-13
Posts: 311
Loc: STRASBOURG, France
|
I have made a function using WMI to read value in the registry. Here is the code with examples.break on
$=SetOption( "Explicit", "ON" )
$=SetOption( "NoVarsInStrings", "ON" )
$=SetOption( "NoMacrosInStrings", "ON" )
global $HKEY_CLASSES_ROOT, $HKEY_CURRENT_USER, $HKEY_LOCAL_MACHINE
global $HKEY_USERS, $HKEY_CURRENT_CONFIG
$HKEY_CLASSES_ROOT = (CDBL(2147483647)+1) ; &80000000
$HKEY_CURRENT_USER = (CDBL(2147483647)+2) ; &80000001
$HKEY_LOCAL_MACHINE = (CDBL(2147483647)+3) ; &80000002
$HKEY_USERS = (CDBL(2147483647)+4) ; &80000003
$HKEY_CURRENT_CONFIG = (CDBL(2147483647)+6) ; &80000005
global $strComputer, $strRegKey, $strRegValueName, $strRegValueType, $RegValue, $tmp
$strComputer = "."
?
";--------------------------------------" ?
"; example 1 : REG_SZ" ?
";--------------------------------------" ?
$strRegKey = "System\CurrentControlSet\Services\TCPIP\Performance"
$strRegValueName = "Open"
$strRegValueType = "REG_SZ"
". SubKeyName : " $strRegKey ?
". ValueName : " $strRegValueName ?
$RegValue = ReadRegistryValue( "HKLM", $strRegkey, $strRegValueName, $strRegValueType, $strComputer )
". value : " $RegValue ?
$RegValue = ReadRegistryValue( $HKEY_LOCAL_MACHINE, $strRegkey, $strRegValueName, $strRegValueType, $strComputer )
". value : " $RegValue ?
?
";--------------------------------------" ?
"; example 2 : REG_DWORD" ?
";--------------------------------------" ?
$strRegKey = "System\CurrentControlSet\Services\TCPIP\Performance"
$strRegValueName = "WbemAdapStatus"
$strRegValueType = "REG_DWORD"
". SubKeyName : " $strRegKey ?
". ValueName : " $strRegValueName ?
$RegValue = ReadRegistryValue( "HKLM", $strRegkey, $strRegValueName, $strRegValueType, $strComputer )
". value : " $RegValue ?
$RegValue = ReadRegistryValue( $HKEY_LOCAL_MACHINE, $strRegkey, $strRegValueName, $strRegValueType, $strComputer )
". value : " $RegValue ?
?
";--------------------------------------" ?
"; example 3 : REG_BINARY" ?
";--------------------------------------" ?
$strRegKey = "System\CurrentControlSet\Services\TCPIP\Performance"
$strRegValueName = "WbemAdapFileSignature"
$strRegValueType = "REG_BINARY"
". SubKeyName : " $strRegKey ?
". ValueName : " $strRegValueName ?
$RegValue = ReadRegistryValue( "HKLM", $strRegkey, $strRegValueName, $strRegValueType, $strComputer )
". value : "
for each $tmp in $regvalue
DecToHex($tmp) " "
next
?
$RegValue = ReadRegistryValue( $HKEY_LOCAL_MACHINE, $strRegkey, $strRegValueName, $strRegValueType, $strComputer )
". value : "
for each $tmp in $regvalue
DecToHex($tmp) " "
next
?
?
";--------------------------------------" ?
"; example 4 : REG_EXPAND_SZ" ?
";--------------------------------------" ?
$strRegKey = "System\CurrentControlSet\Services\TCPIP\Parameters"
$strRegValueName = "DataBasePath"
$strRegValueType = "REG_EXPAND_SZ"
". SubKeyName : " $strRegKey ?
". ValueName : " $strRegValueName ?
$RegValue = ReadRegistryValue( "HKLM", $strRegkey, $strRegValueName, $strRegValueType, $strComputer )
". value : " $RegValue ?
$RegValue = ReadRegistryValue( $HKEY_LOCAL_MACHINE, $strRegkey, $strRegValueName, $strRegValueType, $strComputer )
". value : " $RegValue ?
?
";--------------------------------------" ?
"; example 5 : REG_MULTI_SZ" ?
";--------------------------------------" ?
$strRegKey = "SYSTEM\CurrentControlSet\Services\Eventlog\Security"
$strRegValueName = "Sources"
$strRegValueType = "REG_MULTI_SZ"
". SubKeyName : " $strRegKey ?
". ValueName : " $strRegValueName ?
$RegValue = ReadRegistryValue( "HKLM", $strRegkey, $strRegValueName, $strRegValueType, $strComputer )
". value : "
for each $tmp in $regvalue
? " . " $tmp
next
?
$RegValue = ReadRegistryValue( $HKEY_LOCAL_MACHINE, $strRegkey, $strRegValueName, $strRegValueType, $strComputer )
". value : "
for each $tmp in $regvalue
? " . " $tmp
next
?
exit 0
;-------------------------------------------------------------------------------
; function to read value in the registry (locally or remotely)
;-------------------------------------------------------------------------------
function ReadRegistryValue( $Hive, $strRegkey, $strRegValueName, $strRegType, optional $strComputer )
dim $namespace, $objWMIService, $objRegistry, $hDefKey, $wmiclass, $wmimethod
dim $objInParams, $objOutParams
select
case vartype($hive)=8
select
case $Hive = "HKEY_CLASSES_ROOT" $hDefKey = (CDBL(2147483647)+1) ; &80000000
case $Hive = "HKCR" $hDefKey = (CDBL(2147483647)+1) ; &80000000
case $Hive = "HKEY_CURRENT_USER" $hDefKey = (CDBL(2147483647)+2) ; &80000001
case $Hive = "HKCU" $hDefKey = (CDBL(2147483647)+2) ; &80000001
case $Hive = "HKEY_LOCAL_MACHINE" $hDefKey = (CDBL(2147483647)+3) ; &80000002
case $Hive = "HKLM" $hDefKey = (CDBL(2147483647)+3) ; &80000002
case $Hive = "HKEY_USERS" $hDefKey = (CDBL(2147483647)+4) ; &80000003
case $Hive = "HKUS" $hDefKey = (CDBL(2147483647)+4) ; &80000003
case $Hive = "HKEY_CURRENT_CONFIG" $hDefKey = (CDBL(2147483647)+6) ; &80000005
case $Hive = "HKCC" $hDefKey = (CDBL(2147483647)+6) ; &80000005
case 1 exit -1
endselect
case vartype($hive)=5
$hDefKey = $hive
case 1 exit -1
endselect
select
case $strRegType = "REG_SZ" $wmimethod = "GetStringValue"
case $strRegType = "REG_EXPAND_SZ" $wmimethod = "GetExpandedStringValue"
case $strRegType = "REG_MULTI_SZ" $wmimethod = "GetMultiStringValue"
case $strRegType = "REG_DWORD" $wmimethod = "GetDwordValue"
case $strRegType = "REG_QWORD" $wmimethod = "GetQwordValue"
case $strRegType = "REG_BINARY" $wmimethod = "GetBinaryValue"
case 1 exit -2
endselect
;-- Connect to WMI --
$namespace = "root\default"
$objWMIService = GetObject('winmgmts:{impersonationLevel=impersonate,(debug,security)}!\\'+$strComputer+'\'+$namespace)
$wmiclass = "StdRegProv"
$objRegistry = $objWMIService.Get($wmiclass)
$objInParams = $objRegistry.Methods_($wmimethod).InParameters.SpawnInstance_
$objInParams.hDefKey = $hDefKey
$objInParams.sSubKeyName = $strRegKey
$objInParams.sValueName = $strRegValueName
;-- Execute the method to read value in the registry --
$objOutParams = $objWMIService.ExecMethod( $wmiclass, $wmimethod, $objInParams )
;-- get the Value parameter that is returned by method --
select
case $strRegType = "REG_SZ" $ReadRegistryValue = $objOutParams.sValue
case $strRegType = "REG_EXPAND_SZ" $ReadRegistryValue = $objOutParams.sValue
case $strRegType = "REG_MULTI_SZ" $ReadRegistryValue = $objOutParams.sValue
case $strRegType = "REG_DWORD" $ReadRegistryValue = $objOutParams.uValue
case $strRegType = "REG_QWORD" $ReadRegistryValue = $objOutParams.uValue
case $strRegType = "REG_BINARY" $ReadRegistryValue = $objOutParams.uValue
endselect
endfunction
it is possible to find dynamically the type of a value but with wmi, it is not optimized. I should enum all values of a key to get value name AND type. Then find the requested value in the array of value names and the read type in the array of value type. may be in a new version of the function (like ReadRegistryValueEx) !!!
_________________________
Christophe
|
|
Top
|
|
|
|
#209310 - 2014-07-30 07:11 PM
Re: Can functions have an OUT parameter
[Re: Allen]
|
ChristopheM
Hey THIS is FUN
   
Registered: 2002-05-13
Posts: 311
Loc: STRASBOURG, France
|
Allen,
Here is the code with EnumValues. I implement this in the ReadRegistryValueEx function. I also have updated the examples.break on
$=SetOption( "Explicit", "ON" )
$=SetOption( "NoVarsInStrings", "ON" )
$=SetOption( "NoMacrosInStrings", "ON" )
global $HKEY_CLASSES_ROOT, $HKEY_CURRENT_USER, $HKEY_LOCAL_MACHINE
global $HKEY_USERS, $HKEY_CURRENT_CONFIG
$HKEY_CLASSES_ROOT = (CDBL(2147483647)+1) ; &80000000
$HKEY_CURRENT_USER = (CDBL(2147483647)+2) ; &80000001
$HKEY_LOCAL_MACHINE = (CDBL(2147483647)+3) ; &80000002
$HKEY_USERS = (CDBL(2147483647)+4) ; &80000003
$HKEY_CURRENT_CONFIG = (CDBL(2147483647)+6) ; &80000005
global $strComputer, $strRegKey, $strRegValueName, $strRegValueType, $RegValue, $tmp
$strComputer = "."
?
";--------------------------------------" ?
"; example 1 : REG_SZ" ?
";--------------------------------------" ?
$strRegKey = "System\CurrentControlSet\Services\TCPIP\Performance"
$strRegValueName = "Open"
$strRegValueType = "REG_SZ"
". SubKeyName : " $strRegKey ?
". ValueName : " $strRegValueName ?
$RegValue = ReadRegistryValue( "HKLM", $strRegkey, $strRegValueName, $strRegValueType, $strComputer )
". value : " $RegValue ?
$RegValue = ReadRegistryValue( $HKEY_LOCAL_MACHINE, $strRegkey, $strRegValueName, $strRegValueType, $strComputer )
". value : " $RegValue ?
$RegValue = ReadRegistryValueEx( $HKEY_LOCAL_MACHINE, $strRegkey, $strRegValueName, $strComputer )
". value : " $RegValue ?
?
";--------------------------------------" ?
"; example 2 : REG_DWORD" ?
";--------------------------------------" ?
$strRegKey = "System\CurrentControlSet\Services\TCPIP\Performance"
$strRegValueName = "WbemAdapStatus"
$strRegValueType = "REG_DWORD"
". SubKeyName : " $strRegKey ?
". ValueName : " $strRegValueName ?
$RegValue = ReadRegistryValue( "HKLM", $strRegkey, $strRegValueName, $strRegValueType, $strComputer )
". value : " $RegValue ?
$RegValue = ReadRegistryValue( $HKEY_LOCAL_MACHINE, $strRegkey, $strRegValueName, $strRegValueType, $strComputer )
". value : " $RegValue ?
$RegValue = ReadRegistryValueEx( $HKEY_LOCAL_MACHINE, $strRegkey, $strRegValueName, $strComputer )
". value : " $RegValue ?
?
";--------------------------------------" ?
"; example 3 : REG_BINARY" ?
";--------------------------------------" ?
$strRegKey = "System\CurrentControlSet\Services\TCPIP\Performance"
$strRegValueName = "WbemAdapFileSignature"
$strRegValueType = "REG_BINARY"
". SubKeyName : " $strRegKey ?
". ValueName : " $strRegValueName ?
$RegValue = ReadRegistryValue( "HKLM", $strRegkey, $strRegValueName, $strRegValueType, $strComputer )
". value : "
for each $tmp in $regvalue
DecToHex($tmp) " "
next
?
$RegValue = ReadRegistryValue( $HKEY_LOCAL_MACHINE, $strRegkey, $strRegValueName, $strRegValueType, $strComputer )
". value : "
for each $tmp in $regvalue
DecToHex($tmp) " "
next
?
$RegValue = ReadRegistryValueEx( $HKEY_LOCAL_MACHINE, $strRegkey, $strRegValueName, $strComputer )
". value : "
for each $tmp in $regvalue
DecToHex($tmp) " "
next
?
?
";--------------------------------------" ?
"; example 4 : REG_EXPAND_SZ" ?
";--------------------------------------" ?
$strRegKey = "System\CurrentControlSet\Services\TCPIP\Parameters"
$strRegValueName = "DataBasePath"
$strRegValueType = "REG_EXPAND_SZ"
". SubKeyName : " $strRegKey ?
". ValueName : " $strRegValueName ?
$RegValue = ReadRegistryValue( "HKLM", $strRegkey, $strRegValueName, $strRegValueType, $strComputer )
". value : " $RegValue ?
$RegValue = ReadRegistryValue( $HKEY_LOCAL_MACHINE, $strRegkey, $strRegValueName, $strRegValueType, $strComputer )
". value : " $RegValue ?
$RegValue = ReadRegistryValueEx( $HKEY_LOCAL_MACHINE, $strRegkey, $strRegValueName, $strComputer )
". value : " $RegValue ?
?
";--------------------------------------" ?
"; example 5 : REG_MULTI_SZ" ?
";--------------------------------------" ?
$strRegKey = "SYSTEM\CurrentControlSet\Services\Eventlog\Security"
$strRegValueName = "Sources"
$strRegValueType = "REG_MULTI_SZ"
". SubKeyName : " $strRegKey ?
". ValueName : " $strRegValueName ?
$RegValue = ReadRegistryValue( "HKLM", $strRegkey, $strRegValueName, $strRegValueType, $strComputer )
". value : "
for each $tmp in $regvalue
? " . " $tmp
next
?
$RegValue = ReadRegistryValue( $HKEY_LOCAL_MACHINE, $strRegkey, $strRegValueName, $strRegValueType, $strComputer )
". value : "
for each $tmp in $regvalue
? " . " $tmp
next
?
$RegValue = ReadRegistryValueEx( $HKEY_LOCAL_MACHINE, $strRegkey, $strRegValueName, $strComputer )
". value : "
for each $tmp in $regvalue
? " . " $tmp
next
?
exit 0
;-------------------------------------------------------------------------------
; function to read value in the registry (locally or remotely)
;-------------------------------------------------------------------------------
function ReadRegistryValue( $Hive, $strRegkey, $strRegValueName, $strRegType, optional $strComputer )
dim $namespace, $objWMIService, $objRegistry, $hDefKey, $wmiclass, $wmimethod
dim $objInParams, $objOutParams
$ReadRegistryValue = ""
select
case vartype($hive)=8
select
case $Hive = "HKEY_CLASSES_ROOT" $hDefKey = (CDBL(2147483647)+1) ; &80000000
case $Hive = "HKCR" $hDefKey = (CDBL(2147483647)+1) ; &80000000
case $Hive = "HKEY_CURRENT_USER" $hDefKey = (CDBL(2147483647)+2) ; &80000001
case $Hive = "HKCU" $hDefKey = (CDBL(2147483647)+2) ; &80000001
case $Hive = "HKEY_LOCAL_MACHINE" $hDefKey = (CDBL(2147483647)+3) ; &80000002
case $Hive = "HKLM" $hDefKey = (CDBL(2147483647)+3) ; &80000002
case $Hive = "HKEY_USERS" $hDefKey = (CDBL(2147483647)+4) ; &80000003
case $Hive = "HKUS" $hDefKey = (CDBL(2147483647)+4) ; &80000003
case $Hive = "HKEY_CURRENT_CONFIG" $hDefKey = (CDBL(2147483647)+6) ; &80000005
case $Hive = "HKCC" $hDefKey = (CDBL(2147483647)+6) ; &80000005
case 1 exit -1
endselect
case vartype($hive)=5
$hDefKey = $hive
case 1 exit -1
endselect
select
case $strRegType = "REG_SZ" $wmimethod = "GetStringValue"
case $strRegType = "REG_EXPAND_SZ" $wmimethod = "GetExpandedStringValue"
case $strRegType = "REG_MULTI_SZ" $wmimethod = "GetMultiStringValue"
case $strRegType = "REG_DWORD" $wmimethod = "GetDwordValue"
case $strRegType = "REG_QWORD" $wmimethod = "GetQwordValue"
case $strRegType = "REG_BINARY" $wmimethod = "GetBinaryValue"
case 1 exit -2
endselect
;-- Connect to WMI --
$namespace = "root\default"
$objWMIService = GetObject('winmgmts:{impersonationLevel=impersonate,(debug,security)}!\\'+$strComputer+'\'+$namespace)
$wmiclass = "StdRegProv"
$objRegistry = $objWMIService.Get($wmiclass)
$objInParams = $objRegistry.Methods_($wmimethod).InParameters.SpawnInstance_
$objInParams.hDefKey = $hDefKey
$objInParams.sSubKeyName = $strRegKey
$objInParams.sValueName = $strRegValueName
;-- Execute the method to read value in the registry --
$objOutParams = $objWMIService.ExecMethod( $wmiclass, $wmimethod, $objInParams )
if $objOutParams.ReturnValue <> 0
exit $objOutParams.ReturnValue
endif
;-- get the Value parameter that is returned by method --
select
case $strRegType = "REG_SZ" $ReadRegistryValue = $objOutParams.sValue
case $strRegType = "REG_EXPAND_SZ" $ReadRegistryValue = $objOutParams.sValue
case $strRegType = "REG_MULTI_SZ" $ReadRegistryValue = $objOutParams.sValue
case $strRegType = "REG_DWORD" $ReadRegistryValue = $objOutParams.uValue
case $strRegType = "REG_QWORD" $ReadRegistryValue = $objOutParams.uValue
case $strRegType = "REG_BINARY" $ReadRegistryValue = $objOutParams.uValue
endselect
exit 0
endfunction
;-------------------------------------------------------------------------------
; function to read value in the registry (locally or remotely)
;-------------------------------------------------------------------------------
function ReadRegistryValueEx( $Hive, $strRegkey, $strRegValueName, optional $strComputer )
dim $namespace, $objWMIService, $objRegistry
dim $hDefKey, $arrValuesName, $arrValuesType, $RegType, $wmiclass, $wmimethod
dim $objInParams, $objOutParams
$ReadRegistryValueEx = ""
select
case vartype($hive)=8
select
case $Hive = "HKEY_CLASSES_ROOT" $hDefKey = (CDBL(2147483647)+1) ; &80000000
case $Hive = "HKCR" $hDefKey = (CDBL(2147483647)+1) ; &80000000
case $Hive = "HKEY_CURRENT_USER" $hDefKey = (CDBL(2147483647)+2) ; &80000001
case $Hive = "HKCU" $hDefKey = (CDBL(2147483647)+2) ; &80000001
case $Hive = "HKEY_LOCAL_MACHINE" $hDefKey = (CDBL(2147483647)+3) ; &80000002
case $Hive = "HKLM" $hDefKey = (CDBL(2147483647)+3) ; &80000002
case $Hive = "HKEY_USERS" $hDefKey = (CDBL(2147483647)+4) ; &80000003
case $Hive = "HKUS" $hDefKey = (CDBL(2147483647)+4) ; &80000003
case $Hive = "HKEY_CURRENT_CONFIG" $hDefKey = (CDBL(2147483647)+6) ; &80000005
case $Hive = "HKCC" $hDefKey = (CDBL(2147483647)+6) ; &80000005
case 1 exit -1
endselect
case vartype($hive)=5
$hDefKey = $hive
case 1 exit -1
endselect
;-- Connect to WMI --
$namespace = "root\default"
$objWMIService = GetObject('winmgmts:{impersonationLevel=impersonate,(debug,security)}!\\'+$strComputer+'\'+$namespace)
$wmiclass = "StdRegProv"
$objRegistry = $objWMIService.Get($wmiclass)
$wmimethod = "EnumValues"
$objInParams = $objRegistry.Methods_($wmimethod).InParameters.SpawnInstance_
$objInParams.hDefKey = $hDefKey
$objInParams.sSubKeyName = $strRegKey
$objInParams.sValueName = $strRegValueName
;-- Execute the method to read value in the registry --
$objOutParams = $objWMIService.ExecMethod( $wmiclass, $wmimethod, $objInParams )
if $objOutParams.ReturnValue <> 0
exit -3
endif
;-- search $strRegValueName in the array of value name returned --
$arrValuesName = $objOutParams.sNames
$arrValuesType = $objOutParams.Types
dim $i, $imax, $found
$found = 0
$i = -1
$imax = UBound($arrValuesName)
while $i < $imax
$i = $i + 1
if $strRegValueName = $arrValuesName[$i]
$RegType = $arrValuesType[$i]
select
case $RegType = 1 $wmimethod = "GetStringValue"
case $RegType = 2 $wmimethod = "GetExpandedStringValue"
case $RegType = 7 $wmimethod = "GetMultiStringValue"
case $RegType = 4 $wmimethod = "GetDwordValue"
case $RegType = 11 $wmimethod = "GetQwordValue"
case $RegType = 3 $wmimethod = "GetBinaryValue"
endselect
$i = $imax
$found = 1
endif
loop
if not $found
exit -4
endif
$objInParams = $objRegistry.Methods_($wmimethod).InParameters.SpawnInstance_
$objInParams.hDefKey = $hDefKey
$objInParams.sSubKeyName = $strRegKey
$objInParams.sValueName = $strRegValueName
;-- Execute the method to read value in the registry --
$objOutParams = $objWMIService.ExecMethod( $wmiclass, $wmimethod, $objInParams )
if $objOutParams.ReturnValue <> 0
exit $objOutParams.ReturnValue
endif
;-- get the Value parameter that is returned by method --
select
case $RegType = 1 $ReadRegistryValueEx = $objOutParams.sValue
case $RegType = 2 $ReadRegistryValueEx = $objOutParams.sValue
case $RegType = 7 $ReadRegistryValueEx = $objOutParams.sValue
case $RegType = 4 $ReadRegistryValueEx = $objOutParams.uValue
case $RegType = 11 $ReadRegistryValueEx = $objOutParams.uValue
case $RegType = 3 $ReadRegistryValueEx = $objOutParams.uValue
endselect
exit 0
endfunction
I hope this will be helpful for you.
_________________________
Christophe
|
|
Top
|
|
|
|
#209314 - 2014-07-30 09:44 PM
Re: Can functions have an OUT parameter
[Re: ChristopheM]
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4563
Loc: USA
|
Here's a modified version that works exactly like the built in ReadValue(). (Not throughly tested)
function WMIReadValue($strRegkey, $strRegValueName )
dim $namespace, $objWMIService, $objRegistry
dim $hDefKey, $arrValuesName, $arrValuesType, $RegType, $wmiclass, $wmimethod
dim $objInParams, $objOutParams, $Parts, $counter, $tempkey
$Parts=Split($strRegKey,"\")
if $parts[0]="" and $parts[1]=""
$strComputer=$parts[2]
$counter=3
else
$strComputer= "."
endif
$hive=$parts[0+$counter]
for $i=$counter+1 to ubound($parts)
$tempkey=$tempkey + $parts[$i] + "\"
next
$strRegkey=left($tempkey,-1)
$WMIReadValue = ""
select
case vartype($hive)=8
select
case $Hive = "HKEY_CLASSES_ROOT" $hDefKey = (CDBL(2147483647)+1) ; &80000000
case $Hive = "HKCR" $hDefKey = (CDBL(2147483647)+1) ; &80000000
case $Hive = "HKEY_CURRENT_USER" $hDefKey = (CDBL(2147483647)+2) ; &80000001
case $Hive = "HKCU" $hDefKey = (CDBL(2147483647)+2) ; &80000001
case $Hive = "HKEY_LOCAL_MACHINE" $hDefKey = (CDBL(2147483647)+3) ; &80000002
case $Hive = "HKLM" $hDefKey = (CDBL(2147483647)+3) ; &80000002
case $Hive = "HKEY_USERS" $hDefKey = (CDBL(2147483647)+4) ; &80000003
case $Hive = "HKUS" $hDefKey = (CDBL(2147483647)+4) ; &80000003
case $Hive = "HKEY_CURRENT_CONFIG" $hDefKey = (CDBL(2147483647)+6) ; &80000005
case $Hive = "HKCC" $hDefKey = (CDBL(2147483647)+6) ; &80000005
case 1 exit -1
endselect
case vartype($hive)=5
$hDefKey = $hive
case 1 exit -1
endselect
;-- Connect to WMI --
$namespace = "root\default"
$objWMIService = GetObject('winmgmts:{impersonationLevel=impersonate,(debug,security)}!\\'+$strComputer+'\'+$namespace)
$wmiclass = "StdRegProv"
$objRegistry = $objWMIService.Get($wmiclass)
$wmimethod = "EnumValues"
$objInParams = $objRegistry.Methods_($wmimethod).InParameters.SpawnInstance_
$objInParams.hDefKey = $hDefKey
$objInParams.sSubKeyName = $strRegKey
$objInParams.sValueName = $strRegValueName
;-- Execute the method to read value in the registry --
$objOutParams = $objWMIService.ExecMethod( $wmiclass, $wmimethod, $objInParams )
if $objOutParams.ReturnValue <> 0
exit -3
endif
;-- search $strRegValueName in the array of value name returned --
$arrValuesName = $objOutParams.sNames
$arrValuesType = $objOutParams.Types
dim $i, $imax, $found
$found = 0
$i = -1
$imax = UBound($arrValuesName)
while $i < $imax
$i = $i + 1
if $strRegValueName = $arrValuesName[$i]
$RegType = $arrValuesType[$i]
select
case $RegType = 1 $wmimethod = "GetStringValue"
case $RegType = 2 $wmimethod = "GetExpandedStringValue"
case $RegType = 7 $wmimethod = "GetMultiStringValue"
case $RegType = 4 $wmimethod = "GetDwordValue"
case $RegType = 11 $wmimethod = "GetQwordValue"
case $RegType = 3 $wmimethod = "GetBinaryValue"
endselect
$i = $imax
$found = 1
endif
loop
if not $found
exit -4
endif
$objInParams = $objRegistry.Methods_($wmimethod).InParameters.SpawnInstance_
$objInParams.hDefKey = $hDefKey
$objInParams.sSubKeyName = $strRegKey
$objInParams.sValueName = $strRegValueName
;-- Execute the method to read value in the registry --
$objOutParams = $objWMIService.ExecMethod( $wmiclass, $wmimethod, $objInParams )
if $objOutParams.ReturnValue <> 0
exit $objOutParams.ReturnValue
endif
;-- get the Value parameter that is returned by method --
select
case $RegType = 1 $WMIReadValue = $objOutParams.sValue
case $RegType = 2 $WMIReadValue = $objOutParams.sValue
case $RegType = 7 $WMIReadValue = $objOutParams.sValue
case $RegType = 4 $WMIReadValue = $objOutParams.uValue
case $RegType = 11 $WMIReadValue = $objOutParams.uValue
case $RegType = 3 $WMIReadValue = $objOutParams.uValue
endselect
exit 0
endfunction
|
|
Top
|
|
|
|
#209326 - 2014-07-31 08:51 PM
Re: Can functions have an OUT parameter
[Re: Allen]
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11629
Loc: CA
|
I'm guessing here that you're using Windows 7 and Remote Registry is disabled by default. You can enable it on the local computer while logged in with Admin rights or you can enable it with a policy. Then you can use KiXtart to manage registry entries pretty easily. Though cool that this discussion and coding has been posted.
http://technet.microsoft.com/en-us/library/cc754820.aspx
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 758 anonymous users online.
|
|
|