Page 1 of 1 1
Topic Options
#126589 - 2004-09-12 05:43 AM Help with the WMI registry provider
krabourn Offline
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
#126590 - 2004-09-12 06:13 AM Re: Help with the WMI registry provider
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Maybe if we saw the original VBS code we could see what you changed and what you may have missed.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#126591 - 2004-09-12 06:34 AM Re: Help with the WMI registry provider
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
You assign the hex values but because of the limitation on integers, they come across as negative numbers.

'$$HKCR = '$HKCR ?
'$$HKCU = '$HKCU ?
'$$HKLM = '$HKLM ?
'$$HKU = '$HKU ?
'$$HKCC = '$HKCC ?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#126592 - 2004-09-12 01:33 PM Re: Help with the WMI registry provider
krabourn Offline
Hey THIS is FUN
*****

Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
Here is the original vbs code that I found. http://cwashington.netreach.net/depo/view.asp?Index=560&ScriptType=vbscript
_________________________
Kelly

Top
#126593 - 2004-09-12 01:49 PM Re: Help with the WMI registry provider
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
As a good KiXtarter you should always consult our local UDF Forum first before venturing out into the dark territories of VBScripts. See for example fnWMIWriteValue() - Write to a local or remote registry using WMI with authentication
_________________________
There are two types of vessels, submarines and targets.

Top
#126594 - 2004-09-12 02:08 PM Re: Help with the WMI registry provider
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
If you look at the WMI documentation for the EnumKey method you'll see the following parameters:

uint32 EnumKey(uint32 hDefKey,string sSubKeyName,string sNames[]);

...where sNames[] is an output parameter.

Sadly, output parameters are not supported by KiXtart COM.


Top
#126595 - 2004-09-12 02:25 PM Re: Help with the WMI registry provider
krabourn Offline
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
#126596 - 2004-09-12 02:28 PM Re: Help with the WMI registry provider
krabourn Offline
Hey THIS is FUN
*****

Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
Chris S. Thanks, That is what I was afraid of.

I have started looking at the ExecMethod to see if I can get lucky. But I am afraid I might have trouble with the parameter names. We will see.
_________________________
Kelly

Top
#126597 - 2004-09-12 03:04 PM Re: Help with the WMI registry provider
krabourn Offline
Hey THIS is FUN
*****

Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
Chris

I think you know this but there are other ways to get the output parameters. I assume there is a similar function to this one in the UDF section. This is why I have not given up yet.Code:
FUNCTION fnProcessRun($ProcessCommand, $WMIComputerName, OPTIONAL $ProcessHidden, OPTIONAL $ProcessStartDir)
;--- This will start a process on a computer.
IF $ProcessHidden
$objProcStart = $WMIComputerName.Get("Win32_ProcessStartup")
$ProcStartInst = $objProcStart.SpawnInstance_
$ProcStartInst.ShowWindow = "0"
$procStartInst.Put_
ENDIF
$objProc = $WMIComputerName.Get("Win32_Process")
$objProcInst = $ObjProc.Methods_("Create").InParameters.SpawnInstance_
$objProcInst.CommandLine = $ProcessCommand
IF $ProcessStartDir
$objProcInst.CurrentDirectory = $ProcessStartDir
ENDIF
IF $ProcessHidden
$objProcInst.ProcessStartupInformation = $ProcStartInst
ENDIF
$objProcOut = $WMIComputerName.ExecMethod("Win32_Process","Create",$objProcInst)
$fnProcessRunError = @Error
$fnProcessRun = $objProcOut.Processid
; $pid = $objProcOut.Processid
; $owner = $WMIComputerName.Get("Win32_Process=$pid").ExecMethod_("GetOwner")
;? "Process " + $pid + " was created by " + $owner.domain + "\" + $owner.user + "."
EXIT $fnProcessRunError
ENDFUNCTION

_________________________
Kelly

Top
#126598 - 2004-09-12 07:52 PM Re: Help with the WMI registry provider
krabourn Offline
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
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 874 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.094 seconds in which 0.062 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org