Writing a REG_MULTI_SZ value to registry from WSH 
Author Message
 Writing a REG_MULTI_SZ value to registry from WSH

A REG_MULTI_SZ value is in the form:

string1+null+string2+null+...+stringn+null+null

so once you RegRead one...

arValues = split(valueFromRegRead,Chr(0))

and ignore the last element in the array (it'll be empty since the string being
split ends with 2 consecutive nulls.

To create a string to write, just reverse to process:

valueToRegWrite = string1 & chr(0) & string2 & chr(0) & ... & stringn & chr(0) &
chr(0)

--
Michael Harris

| Does anyone know how to write a REG_MULTI_SZ value to the registry from WSH?
| I've tried WShell.RegWrite but it doesn't support this registry type.
|
| The sample code below fails on the RegWrite method.
|
|     Anders Heick
|
| Samplecode:
| ---------------------
| constRegPath =
| "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ContentIndex\"
|
| Set WshShell = CreateObject("WScript.Shell")
|
| arDLLs = WshShell.RegRead(constRegPath + "DLLsToRegister")
| For Each strDLL in arDLLs
|   Wscript.echo "DLLs: " & strDLL
| Next
|
| Wscript.echo VarType(arDLLs)
|
| WshShell.RegWrite constRegPath + "DLLsToRegister", arDLLs
|
| Set WshShell = Nothing
|
|
|



Thu, 07 Feb 2002 03:00:00 GMT  
 Writing a REG_MULTI_SZ value to registry from WSH
Unfortunately, the method I described works only for _reading_ registry values
that are REG_MULTI_SZ type.  RegWrite does not support _writing_ REG_MULTI_SZ
(not sure why since you can create the a REG_MULTI_SZ value in the right format
in script).

For REG_BINARY, RegRead returns an array of bytes that you can iterate over.
You can RegWrite integers and longs as REG_BINARY, but in VBScript you can't
_create_ an arbitrarily sized array of bytes to RegWrite (assuming it would
accept it).  To write arbitrary REG_BINARY values, you'll need to resort to
creating a temp.reg file and merging it with regedit /s temp.reg.

--
Michael Harris

| No go...
|
| 1) split(valueFromRegRead,Chr(0))  fails with a "VB Runtime - Type
| Mismatch" - (not a problem since the For Each construction works fine on the
| data returned from the RegRead methong.)
|
| 2) Using RegWrite to write the chr(0) separated string changes the registry
| to a REG_SZ if no type is supplied. Trying to write it as a REG_BINARY fails
| with another "VB Runtime - Type Mismatch"
|
| Look like it isn't possible using the RegWrite method - do you know of any
| other method (except the one where I program the object myself...)
|
| ---
| Anders Heick
|


| > A REG_MULTI_SZ value is in the form:
| >
| > string1+null+string2+null+...+stringn+null+null
| >
| > so once you RegRead one...
| >
| > arValues = split(valueFromRegRead,Chr(0))
| >
| > and ignore the last element in the array (it'll be empty since the string
| being
| > split ends with 2 consecutive nulls.
| >
| > To create a string to write, just reverse to process:
| >
| > valueToRegWrite = string1 & chr(0) & string2 & chr(0) & ... & stringn &
| chr(0) &
| > chr(0)
| >
| > --
| > Michael Harris
| >
| >
| >


| > | Does anyone know how to write a REG_MULTI_SZ value to the registry from
| WSH?
| > | I've tried WShell.RegWrite but it doesn't support this registry type.
| > |
| > | The sample code below fails on the RegWrite method.
| > |
| > |     Anders Heick
| > |
| > | Samplecode:
| > | ---------------------
| > | constRegPath =
| > | "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ContentIndex\"
| > |
| > | Set WshShell = CreateObject("WScript.Shell")
| > |
| > | arDLLs = WshShell.RegRead(constRegPath + "DLLsToRegister")
| > | For Each strDLL in arDLLs
| > |   Wscript.echo "DLLs: " & strDLL
| > | Next
| > |
| > | Wscript.echo VarType(arDLLs)
| > |
| > | WshShell.RegWrite constRegPath + "DLLsToRegister", arDLLs
| > |
| > | Set WshShell = Nothing
| > |
| > |
| > |
| >
| >
|
|



Thu, 07 Feb 2002 03:00:00 GMT  
 Writing a REG_MULTI_SZ value to registry from WSH
Just an FYI - I did a little experimenting with the "RegObj.Registry" COM
component...

It handles REG_MULTI_SZ fine for both read/write from VBScript.

But for REG_BINARY, it reads arbitrary values back as byte arrays (just like
RegRead), but I can't get it to accept any VBScript supported type for writing.
Of course this server was written as an unsupported component for VB clients to
start with, so I'll assume it wants a byte array which a VB client can create.

Maybe WSH3 will have better registry support...

--
Michael Harris


| Unfortunately, the method I described works only for _reading_ registry values
| that are REG_MULTI_SZ type.  RegWrite does not support _writing_ REG_MULTI_SZ
| (not sure why since you can create the a REG_MULTI_SZ value in the right
format
| in script).
|
| For REG_BINARY, RegRead returns an array of bytes that you can iterate over.
| You can RegWrite integers and longs as REG_BINARY, but in VBScript you can't
| _create_ an arbitrarily sized array of bytes to RegWrite (assuming it would
| accept it).  To write arbitrary REG_BINARY values, you'll need to resort to
| creating a temp.reg file and merging it with regedit /s temp.reg.
|
| --
| Michael Harris
|
|
|


| | No go...
| |
| | 1) split(valueFromRegRead,Chr(0))  fails with a "VB Runtime - Type
| | Mismatch" - (not a problem since the For Each construction works fine on the
| | data returned from the RegRead methong.)
| |
| | 2) Using RegWrite to write the chr(0) separated string changes the registry
| | to a REG_SZ if no type is supplied. Trying to write it as a REG_BINARY fails
| | with another "VB Runtime - Type Mismatch"
| |
| | Look like it isn't possible using the RegWrite method - do you know of any
| | other method (except the one where I program the object myself...)
| |
| | ---
| | Anders Heick
| |


| | > A REG_MULTI_SZ value is in the form:
| | >
| | > string1+null+string2+null+...+stringn+null+null
| | >
| | > so once you RegRead one...
| | >
| | > arValues = split(valueFromRegRead,Chr(0))
| | >
| | > and ignore the last element in the array (it'll be empty since the string
| | being
| | > split ends with 2 consecutive nulls.
| | >
| | > To create a string to write, just reverse to process:
| | >
| | > valueToRegWrite = string1 & chr(0) & string2 & chr(0) & ... & stringn &
| | chr(0) &
| | > chr(0)
| | >
| | > --
| | > Michael Harris
| | >
| | >
| | >


| | > | Does anyone know how to write a REG_MULTI_SZ value to the registry from
| | WSH?
| | > | I've tried WShell.RegWrite but it doesn't support this registry type.
| | > |
| | > | The sample code below fails on the RegWrite method.
| | > |
| | > |     Anders Heick
| | > |
| | > | Samplecode:
| | > | ---------------------
| | > | constRegPath =
| | > | "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ContentIndex\"
| | > |
| | > | Set WshShell = CreateObject("WScript.Shell")
| | > |
| | > | arDLLs = WshShell.RegRead(constRegPath + "DLLsToRegister")
| | > | For Each strDLL in arDLLs
| | > |   Wscript.echo "DLLs: " & strDLL
| | > | Next
| | > |
| | > | Wscript.echo VarType(arDLLs)
| | > |
| | > | WshShell.RegWrite constRegPath + "DLLsToRegister", arDLLs
| | > |
| | > | Set WshShell = Nothing
| | > |
| | > |
| | > |
| | >
| | >
| |
| |
|
|



Thu, 07 Feb 2002 03:00:00 GMT  
 Writing a REG_MULTI_SZ value to registry from WSH
Does anyone know how to write a REG_MULTI_SZ value to the registry from WSH?
I've tried WShell.RegWrite but it doesn't support this registry type.

The sample code below fails on the RegWrite method.

    Anders Heick

Samplecode:
---------------------
constRegPath =
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ContentIndex\"

Set WshShell = CreateObject("WScript.Shell")

arDLLs = WshShell.RegRead(constRegPath + "DLLsToRegister")
For Each strDLL in arDLLs
  Wscript.echo "DLLs: " & strDLL
Next

Wscript.echo VarType(arDLLs)

WshShell.RegWrite constRegPath + "DLLsToRegister", arDLLs

Set WshShell = Nothing



Fri, 08 Feb 2002 03:00:00 GMT  
 Writing a REG_MULTI_SZ value to registry from WSH
No go...

1) split(valueFromRegRead,Chr(0))  fails with a "VB Runtime - Type
Mismatch" - (not a problem since the For Each construction works fine on the
data returned from the RegRead methong.)

2) Using RegWrite to write the chr(0) separated string changes the registry
to a REG_SZ if no type is supplied. Trying to write it as a REG_BINARY fails
with another "VB Runtime - Type Mismatch"

Look like it isn't possible using the RegWrite method - do you know of any
other method (except the one where I program the object myself...)

---
Anders Heick


Quote:
> A REG_MULTI_SZ value is in the form:

> string1+null+string2+null+...+stringn+null+null

> so once you RegRead one...

> arValues = split(valueFromRegRead,Chr(0))

> and ignore the last element in the array (it'll be empty since the string
being
> split ends with 2 consecutive nulls.

> To create a string to write, just reverse to process:

> valueToRegWrite = string1 & chr(0) & string2 & chr(0) & ... & stringn &
chr(0) &
> chr(0)

> --
> Michael Harris




- Show quoted text -

Quote:
> | Does anyone know how to write a REG_MULTI_SZ value to the registry from
WSH?
> | I've tried WShell.RegWrite but it doesn't support this registry type.
> |
> | The sample code below fails on the RegWrite method.
> |
> |     Anders Heick
> |
> | Samplecode:
> | ---------------------
> | constRegPath =
> | "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ContentIndex\"
> |
> | Set WshShell = CreateObject("WScript.Shell")
> |
> | arDLLs = WshShell.RegRead(constRegPath + "DLLsToRegister")
> | For Each strDLL in arDLLs
> |   Wscript.echo "DLLs: " & strDLL
> | Next
> |
> | Wscript.echo VarType(arDLLs)
> |
> | WshShell.RegWrite constRegPath + "DLLsToRegister", arDLLs
> |
> | Set WshShell = Nothing
> |
> |
> |



Fri, 08 Feb 2002 03:00:00 GMT  
 Writing a REG_MULTI_SZ value to registry from WSH
With other tools...

rundll32 setupapi,InstallHinfSection DefaultInstall 128 .\myfile.inf

myfile.inf
~~~~~~~~~~~~~~~~~~~~~~~
; File created with sysdiff version 40007

[Version]
Signature = "$Windows NT$"

[DefaultInstall]
AddReg = AddReg

[AddReg]
HKLM,"SOFTWARE\MYCompany\Key,"Value",FLG_ADDREG_APPEND,"AppendedStr"
~~~~~~~~~~~~~~~~~~~

Quote:

>Does anyone know how to write a REG_MULTI_SZ value to the registry from
WSH?
>I've tried WShell.RegWrite but it doesn't support this registry type.

>The sample code below fails on the RegWrite method.

>    Anders Heick

>Samplecode:
>---------------------
>constRegPath =
>"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ContentIndex\"

>Set WshShell = CreateObject("WScript.Shell")

>arDLLs = WshShell.RegRead(constRegPath + "DLLsToRegister")
>For Each strDLL in arDLLs
>  Wscript.echo "DLLs: " & strDLL
>Next

>Wscript.echo VarType(arDLLs)

>WshShell.RegWrite constRegPath + "DLLsToRegister", arDLLs

>Set WshShell = Nothing



Fri, 08 Feb 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Writing a REG_MULTI_SZ Value to the registry

2. Problem writing binary registry of type reg_multi_sz?

3. Using REG_MULTI_SZ registry values

4. Copying REG_MULTI_SZ values from registry

5. Writing REG_MULTI_SZ Reg Value

6. How To Write a Hex Value to Registry

7. How to write binary value to registry with RegWrite

8. How to write the binary values to the registry using vbs

9. Need help on writing binary value to registry

10. Reading/Writing Hex values from the registry

11. Writing REG_BINARY values to the Registry

12. How to write binary-values to registry

 

 
Powered by phpBB® Forum Software