Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


How can this RegKeyExists key be improved?

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,61413
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> How can this RegKeyExists key be improved?
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 How can this RegKeyExists key be improved? - 6/16/2008 12:51:33 AM   
  GreatBarrier86

 

Posts: 71
Score: 0
Joined: 3/10/2008
Status: offline

      


I have a feeling it could be tweaked. Maybe the first thing would be to get rid of the (Hive,Path,Key) and have the function parse all that information. What do you guys think?

I tried the parsing and i am able to get the Hive part, but i am not sure how to get the Path and Key from a single string.
 
 
Post #: 1
 
 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

(in reply to GreatBarrier86)
 
 
Post #: 2
 
 RE: How can this RegKeyExists key be improved? - 6/16/2008 2:13:19 AM   
  GreatBarrier86

 

Posts: 71
Score: 0
Joined: 3/10/2008
Status: offline
What about what i mentioned? Getting rid of the Hive,Path,Key and just using one string?

I'd prefer that, but i dont know how to parse the key and hive out of it.

(in reply to ebgreen)
 
 
Post #: 3
 
 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

(in reply to GreatBarrier86)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> How can this RegKeyExists key be improved? Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts