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!
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
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:
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