Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
const REG_SZ = 1
const REG_EXPAND_SZ = 2
const REG_BINARY = 3
const REG_DWORD = 4
const REG_MULTI_SZ = 7
strOriginalKeyPath = "SOFTWARE\ORACLE"
Function FindKeyValue(strKeyPath)

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
errorCheck = oReg.EnumKey(HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys)

If (errorCheck=0 and IsArray(arrSubKeys)) then
For Each subkey In arrSubKeys
strNewKeyPath = strKeyPath & "\" & subkey
End If
oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, _
arrValueNames, arrValueTypes

If (errorCheck=0 and IsArray(arrValueNames)) then
For i=0 To UBound(arrValueNames)

if arrValueNames(i) = "ORACLE_HOME" then
strValueName = arrValueNames(i)
oReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, dwValue
end if
'msgbox FindKeyValue
End if
end Function

How to get the value of dwvalue out side the function and storing it in the variable...Guy Need An Help
0 Comments   [ - ] Hide Comments


Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
Answer this question or Comment on this question for clarity


Are you not getting the return value from the function?

strRetValue = FindKeyValue(strOriginalKeyPath)
Answered 11/22/2010 by: murali.bhat
Purple Belt

Please log in to comment
- Add 'Option Explicit' as line 1. That forces variable declaration, always a good idea.
- I prefer to return data from functions using a ByRef variable and have the function itself return True or False.
- Make your FindKeyValue more portable by passing in the name of the value you're looking for (in this case "ORACLE_HOME") via a ByVal variable.
- Move the registry object's creation outside the function. It's being created every time the function is called. Alternatively, make sure you set it to Nothing just before the function ends.
- Add LOTS more error-trapping. For example, you don't test whether the registry object got created. Yes, 99.99% of the time it will get created but code should ALWAYS assume the worst.
- Please use the CODE tag for code (and other lengthy text, e.g. log file content)
- There is a dedicated Scripting forum on AD :-)
Answered 11/23/2010 by: VBScab
Red Belt

Please log in to comment