Scripting doubt
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"
FindKeyValue(strOriginalKeyPath)
'-------------------------------------------------------------------------
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
FindKeyValue(strNewKeyPath)
Next
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
FindKeyValue=dwvalue
'msgbox FindKeyValue
Next
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
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"
FindKeyValue(strOriginalKeyPath)
'-------------------------------------------------------------------------
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
FindKeyValue(strNewKeyPath)
Next
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
FindKeyValue=dwvalue
'msgbox FindKeyValue
Next
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
[ + ] Show comments
Answers (2)
Please log in to answer
Posted by:
murali.bhat
14 years ago
Posted by:
anonymous_9363
14 years ago
- 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 :-)
- 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 :-)
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.