Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


correct syntax for registry write script

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> correct syntax for registry write script
  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 >>
 correct syntax for registry write script - 4/26/2006 2:32:45 PM   
  xaviorinc

 

Posts: 25
Score: 0
Joined: 4/24/2006
Status: offline
I have a simple question, regarding registry

I created very simple script which will add the registry key let say HKCU\ZipCode, with value 11223 in


set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKCU\ZipCode", "11223"

Question what would be correct function to check if the key already exist and if not then create it.

function ReadKey(Key)
   on error resume next
   ReadKey = WshShell.RegRead(key)
   if not err.number=0 then
      MsgBox "Couldn't open key """& key & """: " & err.description
      WScript.Quit.
   end if
end function

In my first question i am wondering if i would define key="HKCU\ZipCode" and it would be enough.

Second question, how can i add another value to ZipCode let say "County" and assign value "Kings" to it, all under ZipCode?

Thanks
 
 
Post #: 1
 
 RE: correct syntax for registry write script - 5/1/2006 6:18:31 AM   
  xaviorinc

 

Posts: 25
Score: 0
Joined: 4/24/2006
Status: offline
I am wondering if anyone can suggest the solution for my problem.

Thanks

(in reply to xaviorinc)
 
 
Post #: 2
 
 RE: correct syntax for registry write script - 5/1/2006 6:37:26 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
Google had the answer all along. You should have asked it:

http://www.google.com/search?hl=en&q=vbscript+check+if+registry+key+exists&btnG=Google+Search

~164,000 hits although I think the first one should get you started in the right direction.

_____________________________

"... 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 xaviorinc)
 
 
Post #: 3
 
 RE: correct syntax for registry write script - 5/1/2006 6:47:52 AM   
  xaviorinc

 

Posts: 25
Score: 0
Joined: 4/24/2006
Status: offline
Google is the biggest search engine and i am sure it got tons of resources about registry keys ect.

I have asked two specific questions and for the first gave an example asking if i can use it.

Second question was:

how can i add another value to ZipCode let say "County" and assign value "Kings" to it, all under ZipCode?

I am sure sooner or later someone else will have a similar question and don't you think it would be easier to answer both questions in the formum or just remove it form the forum rather then pasting the URL from google. 


(in reply to ebgreen)
 
 
Post #: 4
 
 RE: correct syntax for registry write script - 5/1/2006 7:14:56 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
Have you tried anything yourself?

This:
WshShell.RegWrite "HKCU\ZipCode", "11223"

Creates a String value in the root of the HKCU hive that has "11223" for it's data.

So the question " how can i add another value to ZipCode let say "County" and assign value "Kings" to it, all under ZipCode?" does not make any sense. You cannot make a value that is a child of another value. Only keys and hives can have children. What exactly do you want? Do you want a key in the root of HKCU whose name is ZipCode and whose default value is the string 11223? In that case, it would make sense to say that you want to make another value in the ZipCode key with the name "County" and string data of "Kings". Is this what you want to do? What exactly have you tried? What exactly were the results from your attempts? Have you read the documentation for the .RegWrite method?

< Message edited by ebgreen -- 5/1/2006 7:16:57 AM >


_____________________________

"... 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 xaviorinc)
 
 
Post #: 5
 
 
 
  

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 >> correct syntax for registry write script 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