#126589 - 2004-09-12 05:43 AM
Help with the WMI registry provider
|
krabourn
Hey THIS is FUN
   
Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
|
I finally decided to see if I could put to use the WMI registry provider since at work there are occasions with RAS clients that I can't get to their registry because network and file sharing is turned off but I can get to WMI.
I stole someone elses vbs code and started with EnumKey but I can't get any values back. I am hoping I am just tired and missing something because of that.
Has anyone tried this before? This is not finished by any means but here is what I have so far. Code:
$Computer = "Computer" $WMIRegComputer = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $Computer + "\root\default:StdRegProv")
$Registry = "\\" + $Computer + "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WBEM"
$RC = fnEnumKey($Registry, $WMIRegComputer) ? UBound($RC) ? Join($RC, @CRLF)
QUIT 1
FUNCTION fnEnumKey($RegKey, $WMIRegComputerName) DIM $HKCR, $HKCU, $HKLM, $HKU, $HKCC $HKCR = &80000000 ;HKEY_CLASSES_ROOT $HKCU = &80000001 ;HKEY_CURRENT_USER $HKLM = &80000002 ;HKEY_LOCAL_MACHINE $HKU = &80000003 ;HKEY_USERS $HKCC = &80000005 ;HKEY_CURRENT_CONFIG
DIM $Key, $SubKey IF VarType($WMIRegComputerName) = 9 SELECT CASE InStr($RegKey, "HKEY_CLASSES_ROOT") > 0 OR InStr($RegKey, "HKCR") > 0 $Key = $HKCR IF InStr($RegKey, "HKCR") > 0 $SubKey = Split($RegKey, "HKCR\")[1] ELSE $SubKey = Split($RegKey, "HKEY_CLASSES_ROOT\")[1] ENDIF CASE InStr($RegKey, "HKEY_CURRENT_USER") > 0 OR InStr($RegKey, "HKCU") > 0 $Key = $HKCU IF InStr($RegKey, "HKCU") > 0 $SubKey = Split($RegKey, "HKCU\")[1] ELSE $SubKey = Split($RegKey, "HKEY_CURRENT_USER\")[1] ENDIF CASE InStr($RegKey, "HKEY_LOCAL_MACHINE") > 0 OR InStr($RegKey, "HKLM") > 0 $Key = $HKLM IF InStr($RegKey, "HKLM") > 0 $SubKey = Split($RegKey, "HKLM\")[1] ELSE $SubKey = Split($RegKey, "HKEY_LOCAL_MACHINE\")[1] ENDIF CASE InStr($RegKey, "HKEY_USERS") > 0 OR InStr($RegKey, "HKU") > 0 $Key = $HKU IF InStr($RegKey, "HKU") > 0 $SubKey = Split($RegKey, "HKU\")[1] ELSE $SubKey = Split($RegKey, "HKEY_USERS\")[1] ENDIF CASE InStr($RegKey, "HKEY_CURRENT_CONFIG") > 0 OR InStr($RegKey, "HKCC") > 0 $Key = $HKCC IF InStr($RegKey, "HKCC") > 0 $SubKey = Split($RegKey, "HKCC\")[1] ELSE $SubKey = Split($RegKey, "HKEY_CURRENT_CONFIG\")[1] ENDIF ENDSELECT
IF $Key <> "" AND $SubKey <> "" DIM $Ret[0] $sKeys = $WMIRegComputerName.EnumKey($Key, $SubKey) REDIM $Ret[UBound($sKeys)] FOR $Count = 0 TO UBound($sKeys) $Ret[$Count] = $sKeys[$Count] NEXT $fnEnumKey = Join($Ret, @CRLF) ENDIF ENDIF ENDFUNCTION
_________________________
Kelly
|
|
Top
|
|
|
|
#126595 - 2004-09-12 02:25 PM
Re: Help with the WMI registry provider
|
krabourn
Hey THIS is FUN
   
Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
|
I saw it and and am using it as a reference. I changed over to using the CINT() values. But, I believe the bigger problem is with getting the return value from EnumKey. The VBS code is Code:
oReg.EnumKey Key,SubKey, sKeys . As we know, I can't get sKeys in kix with this syntax.
Code:
FUNCTION fnEnumKey($RegKey, $WMIRegComputerName) DIM $HKCR, $HKCU, $HKLM, $HKU, $HKCC ; $HKCR = &80000000 ;HKEY_CLASSES_ROOT $HKCR = CInt(2147483648.0) ;&80000000 ;HKEY_CLASSES_ROOT ; $HKCU = &80000001 ;HKEY_CURRENT_USER $HKCU = CInt(2147483649.0) ;&80000001 ;HKEY_CURRENT_USER ; $HKLM = &80000002 ;HKEY_LOCAL_MACHINE $HKLM = CInt(2147483650.0) ;&80000002 ;HKEY_LOCAL_MACHINE ; $HKU = &80000003 ;HKEY_USERS $HKU = CInt(2147483652.0) ;&80000003 ;HKEY_USERS ; $HKCC = &80000005 ;HKEY_CURRENT_CONFIG $HKCC = CInt(2147483653.0) ;&80000005 ;HKEY_CURRENT_CONFIG DIM $Key, $SubKey IF VarType($WMIRegComputerName) = 9 SELECT CASE InStr($RegKey, "HKEY_CLASSES_ROOT") > 0 OR InStr($RegKey, "HKCR") > 0 $Key = $HKCR IF InStr($RegKey, "HKCR") > 0 $SubKey = Split($RegKey, "HKCR\")[1] ELSE $SubKey = Split($RegKey, "HKEY_CLASSES_ROOT\")[1] ENDIF CASE InStr($RegKey, "HKEY_CURRENT_USER") > 0 OR InStr($RegKey, "HKCU") > 0 $Key = $HKCU IF InStr($RegKey, "HKCU") > 0 $SubKey = Split($RegKey, "HKCU\")[1] ELSE $SubKey = Split($RegKey, "HKEY_CURRENT_USER\")[1] ENDIF CASE InStr($RegKey, "HKEY_LOCAL_MACHINE") > 0 OR InStr($RegKey, "HKLM") > 0 $Key = $HKLM IF InStr($RegKey, "HKLM") > 0 $SubKey = Split($RegKey, "HKLM\")[1] ELSE $SubKey = Split($RegKey, "HKEY_LOCAL_MACHINE\")[1] ENDIF CASE InStr($RegKey, "HKEY_USERS") > 0 OR InStr($RegKey, "HKU") > 0 $Key = $HKU IF InStr($RegKey, "HKU") > 0 $SubKey = Split($RegKey, "HKU\")[1] ELSE $SubKey = Split($RegKey, "HKEY_USERS\")[1] ENDIF CASE InStr($RegKey, "HKEY_CURRENT_CONFIG") > 0 OR InStr($RegKey, "HKCC") > 0 $Key = $HKCC IF InStr($RegKey, "HKCC") > 0 $SubKey = Split($RegKey, "HKCC\")[1] ELSE $SubKey = Split($RegKey, "HKEY_CURRENT_CONFIG\")[1] ENDIF ENDSELECT
IF $Key <> "" AND $SubKey <> "" DIM $Ret[0] $sKeys = $WMIRegComputerName.EnumKey($Key, $SubKey) ? VarTypeName($sKeys) ? $sKeys REDIM $Ret[UBound($sKeys)] FOR $Count = 0 TO UBound($sKeys) $Ret[$Count] = $sKeys[$Count] NEXT $fnEnumKey = Join($Ret, @CRLF) ENDIF ENDIF ENDFUNCTION
_________________________
Kelly
|
|
Top
|
|
|
|
#126598 - 2004-09-12 07:52 PM
Re: Help with the WMI registry provider
|
krabourn
Hey THIS is FUN
   
Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
|
Here it is and it works. You can look at this page dealing with jscript, . http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/writing_wmi_scripts_in_jscript.asp Code:
$Computer = "Computer" $WMIRegComputer = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $Computer + "\root\default:StdRegProv")
$Registry = "\\" + $Computer + "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WBEM"
$RC = fnEnumKey($Registry, $WMIRegComputer) ? UBound($RC) ? Join($RC, @CRLF)
QUIT 1
FUNCTION fnEnumKey($RegKey, $WMIRegComputerName) DIM $HKCR, $HKCU, $HKLM, $HKU, $HKCC $HKCR = &80000000 ;HKEY_CLASSES_ROOT ; $HKCR = CInt(2147483648.0) ;&80000000 ;HKEY_CLASSES_ROOT $HKCU = &80000001 ;HKEY_CURRENT_USER ; $HKCU = CInt(2147483649.0) ;&80000001 ;HKEY_CURRENT_USER $HKLM = &80000002 ;HKEY_LOCAL_MACHINE ; $HKLM = CInt(2147483650.0) ;&80000002 ;HKEY_LOCAL_MACHINE $HKU = &80000003 ;HKEY_USERS ; $HKU = CInt(2147483652.0) ;&80000003 ;HKEY_USERS $HKCC = &80000005 ;HKEY_CURRENT_CONFIG ; $HKCC = CInt(2147483653.0) ;&80000005 ;HKEY_CURRENT_CONFIG DIM $Key, $SubKey, $Ubound IF VarType($WMIRegComputerName) = 9 SELECT CASE InStr($RegKey, "HKEY_CLASSES_ROOT") > 0 OR InStr($RegKey, "HKCR") > 0 $Key = $HKCR IF InStr($RegKey, "HKCR") > 0 $SubKey = Split($RegKey, "HKCR\")[1] ELSE $SubKey = Split($RegKey, "HKEY_CLASSES_ROOT\")[1] ENDIF CASE InStr($RegKey, "HKEY_CURRENT_USER") > 0 OR InStr($RegKey, "HKCU") > 0 $Key = $HKCU IF InStr($RegKey, "HKCU") > 0 $SubKey = Split($RegKey, "HKCU\")[1] ELSE $SubKey = Split($RegKey, "HKEY_CURRENT_USER\")[1] ENDIF CASE InStr($RegKey, "HKEY_LOCAL_MACHINE") > 0 OR InStr($RegKey, "HKLM") > 0 $Key = $HKLM IF InStr($RegKey, "HKLM") > 0 $SubKey = Split($RegKey, "HKLM\")[1] ELSE $SubKey = Split($RegKey, "HKEY_LOCAL_MACHINE\")[1] ENDIF CASE InStr($RegKey, "HKEY_USERS") > 0 OR InStr($RegKey, "HKU") > 0 $Key = $HKU IF InStr($RegKey, "HKU") > 0 $SubKey = Split($RegKey, "HKU\")[1] ELSE $SubKey = Split($RegKey, "HKEY_USERS\")[1] ENDIF CASE InStr($RegKey, "HKEY_CURRENT_CONFIG") > 0 OR InStr($RegKey, "HKCC") > 0 $Key = $HKCC IF InStr($RegKey, "HKCC") > 0 $SubKey = Split($RegKey, "HKCC\")[1] ELSE $SubKey = Split($RegKey, "HKEY_CURRENT_CONFIG\")[1] ENDIF ENDSELECT
IF $Key <> "" AND $SubKey <> "" $objMethod = $WMIRegComputerName.Methods_.Item("EnumKey") $objInParam = $objMethod.InParameters.SpawnInstance_() $objInParam.hDefKey = $Key $objInParam.sSubKeyName = $SubKey $objRegOut = $WMIRegComputerName.ExecMethod_($objMethod.Name,$objInParam) $sKeys = $objRegOut.sNames FOR EACH $KeyName IN $sKeys $Ubound = UBound($sKeys) IF $sKeys[$Ubound] > " " $Ubound = $Ubound + 1 REDIM PRESERVE $sKeys[$Ubound] ENDIF $sKeys[$Ubound] = $KeyName NEXT $fnEnumKey = $sKeys ENDIF ENDIF ENDFUNCTION
_________________________
Kelly
|
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 874 anonymous users online.
|
|
|