Link to home
Start Free TrialLog in
Avatar of swartwe
swartwe

asked on

Using WSH to update REG_MULTI_SZ data type

I need to add a registry value which has a data type of REG_MULTI_SZ.  I was hoping to do it with WSH (Windows Scripting Host) using VB but the documentation says that the RegWrite method cannot handle REG_MULTI_SZ data.

Is anyone aware of another means to accomplish this with WSH?
Avatar of ramshank
ramshank

Try the following


RegRead Method
--------------
The following code segment will return the value of the registry key specified in
the strPath variable. The code below can also help in determining the data type
of the key being access. The following table shows the return value when using
the TypeName function on the registry key.

+---------------------------------------------------+
| Registry Key  | Return Data Type (using TypeName) |
+---------------------------------------------------+
| REG_SZ        | String                            |
+---------------------------------------------------+
| REG_EXPAND_SZ | String                            |
+---------------------------------------------------+
| REG_MULTI_SZ  | Variant Array                     |
+---------------------------------------------------+
| REG_DWORD     | Long                              |
+---------------------------------------------------+
| REG_BINARY    | Variant Array                     |
+---------------------------------------------------+

   Set WshShell = CreateObject("WScript.Shell")
   strPath = "HKCU\MyRegKey\Entry\Value1"
   varRegVal = WshShell.RegRead(strPath)
   WScript.Echo TypeName(varRegVal)
   'Check to see if the value is an array of values, then loop through them
   If VarType(varRegVal) And vbArray Then
       For i = LBound(varRegVal) To UBound(varRegVal)
           WScript.Echo varRegVal(i)
       Next
   Else
       WScript.Echo varRegVal
   End If
Avatar of swartwe

ASKER

While I appreciate the response and find it interesting, it does not answer my question ("I need to add a registry value which has a data type of REG_MULTI_SZ.").  Regrettably, I must reject this response.
ASKER CERTIFIED SOLUTION
Avatar of bxt
bxt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of swartwe

ASKER

While my preference was to add a REG_MULTI_SZ string using WSH, as of now, I don't think that it can be done with WSH.  Because of this conclusion, a couple of weeks ago I decided to write my own utility (I used the same API functions which you used in your utility).

I am giving you an excellent grade because you did provide a means by which to accomplish my needs (using the same approach that I ultimately chose).

I appreciate your help along with your offer to send me an exe (However, I won't be needing an exe).  

Thank you.