Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Write a MULTI_SZ value to the Registry

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> Write a MULTI_SZ value to the Registry
  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 >>
 Write a MULTI_SZ value to the Registry - 3/9/2006 7:37:51 AM   
  DiGiTAL.SkReAM


Posts: 1139
Score: 6
Joined: 9/6/2005
From: Florida, USA
Status: offline
Here's a function I wrote that uses WMI to write a MULTI_SZ value to the registry.  Since shell.regwrite doesn't handle MULTI_SZ, I had been just dumping the strings out to a text file that i formatted as a .reg file and importing that.  Well, that works, but it is kludgy as all get-out.
I like this solution much better.
I had to include all of the HKEY values as constants, as this is being used to write values into different keys, so it makes it a bit messier, but.... hey, it works.


      

_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury
 
 
Post #: 1
 
 RE: Write a MULTI_SZ value to the Registry - 3/9/2006 8:11:19 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
A couple of comments:

1) Useful function...thanks for taking the time to share.
2) I think I would just make the function accept an array for the values rather than taking a string and splitting it. That way if I need to write values that have a comma in them there is no issue.
3) I don't think I would use WScript.Quit if there was an invalid path passed in. If you use that and I use your function in my script, then my script would just inexplicably quit if I had a typo in the path. I would use Exit Function istead (in conjuction with the next comment)
4) You never return anything. That being the case, this isn't properly a Function at all it is a Sub. I think that I would keep it as a Function but return a value so that the caller can do rudimentary error checking.

Here is the code with the changes that I would make:

      

_____________________________

"... 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 DiGiTAL.SkReAM)
 
 
Post #: 2
 
 RE: Write a MULTI_SZ value to the Registry - 3/10/2006 5:23:27 AM   
  DiGiTAL.SkReAM


Posts: 1139
Score: 6
Joined: 9/6/2005
From: Florida, USA
Status: offline
Taking into account ebgreen's excellent comments, here is the latest iteration of the FUNCTION.
Here's the documentation:
This function allows the writing of a MULTI_SZ value to the registry.
Usage: fRegSetMULTI_SZ "Registry path and key", array containing values to write
Example: fRegSetMULTI_SZ "HKLM\Software\Microsoft\Windows\CurrentVersion\Testing\MyMultiValueKey",Array
Returns:
0 = Worked properly, no errors
1 = Incorrect hive (HKCR, HKCU, HKLM, etc) 
2 = Error when querying WMI
3 = Error Creating Key.  Check the Key path passed to the Function
4 = Error writing values.  Check the values being passed to the Function.


      


_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: Write a MULTI_SZ value to the Registry - 3/10/2006 5:53:22 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
All I can say is...Sweet!

_____________________________

"... 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 DiGiTAL.SkReAM)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> Write a MULTI_SZ value to the Registry 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