Login | |
|
 |
RE: How can this RegKeyExists key be improved? - 6/16/2008 1:22:45 AM
|
|
 |
|
| |
ebgreen
Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
|
That is a pretty standard implementation. If I were looking to improve it, the first thing that I would do is to get rid of the WScript.Echo and the WScript.Quit. Instead have the function return something that indicates a failure. In my case, most of my functions return an array. The first item in the array is an int. 0 indicates success and anything else is a failure. The second item in the array would be TRUE or FALSE in this case depending on whether the key existsed or not. So then the way you would use the function would be: Dim arrReturn arrReturn = RegKeyExists("HKEY_DOESNOTEXIST", "path\to\some\key", "Value") If arrReturn(0) <> 0 Then 'Put code here to handle a hive that does not exist ElseIf arrReturn(1) = False Then 'Put code here for if the key did not exist Else 'Put code here for if the key does exist End If
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: How can this RegKeyExists key be improved? - 6/16/2008 2:32:49 AM
|
|
 |
|
| |
ebgreen
Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
|
Since you are just doing an exists, it shouldn't be too hard. Let's say that the string was passed in as strEverything. Then: Dim strHive Dim strPath Dim strKey Dim arrParts Dim i arrParts = Split(strEverything, "\") strHive = arrParts(0) strPath = "" For i = 1 To Ubound(arrParts)-1 strPath = strPath & arrParts(i) & "\" Next strKey = arrParts(UBound(arrParts)) That is just the basics. You would want to play around with it to handle any unusual situations.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
|
|