How to write or edit multi-part string in the windows registry

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
migro
Macro Veteran
Posts: 151
Joined: Thu Nov 06, 2003 5:23 pm
Location: Germany
Contact:

How to write or edit multi-part string in the windows registry

Post by migro » Sun Sep 18, 2022 8:15 pm

Hi all,

is there a way to edit or write multi part strings into the windows registry?

regards
migro
regards
migro

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: How to write or edit multi-part string in the windows registry

Post by Dorian (MJT support) » Tue Sep 20, 2022 11:19 am

It isn't possible with RegistryWriteKey so I consulted Marcus and he came up with this for you :

Code: Select all

VBSTART

  Const HKEY_CLASSES_ROOT     = &H80000000
  Const HKEY_CURRENT_USER     = &H80000001
  Const HKEY_LOCAL_MACHINE    = &H80000002
  Const HKEY_USERS            = &H80000003
  Const HKEY_CURRENT_CONFIG   = &H80000005

  Sub WriteMultiSz(rootKeyStr, strKeyPath, strValueName, listStr)

    Select case rootKeyStr
      Case "HKEY_CLASSES_ROOT"
        rootKey = HKEY_CLASSES_ROOT
      Case "HKEY_CURRENT_USER"
        rootKey = HKEY_CURRENT_USER
      Case "HKEY_LOCAL_MACHINE"
        rootKey = HKEY_LOCAL_MACHINE
      Case "HKEY_USERS"
        rootKey = HKEY_USERS
      Case "HKEY_CURRENT_CONFIG"
        rootKey = HKEY_CURRENT_CONFIG
    End Select

    strComputer = "."

    Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
        strComputer & "\root\default:StdRegProv")

    arrStringValues = Split(listStr, vbCRLF)

    oReg.SetMultiStringValue rootKey,strKeyPath,strValueName,arrStringValues

  End Sub

VBEND

//Create a CRLF delimited list of strings
Let>list=first%CRLF%second%CRLF%third

//Write it like this:
VBRun>WriteMultiSz,HKEY_CURRENT_USER,SOFTWARE\MJTNET\MSched15,TestValue2,list
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
migro
Macro Veteran
Posts: 151
Joined: Thu Nov 06, 2003 5:23 pm
Location: Germany
Contact:

Re: How to write or edit multi-part string in the windows registry

Post by migro » Fri Oct 21, 2022 9:58 pm

Hi Dorian,

thx for you reply and the assistance of Marcus. I was not notified about your reply, so sorry for the delay in my answer.

Seems that will be exactly what I need. I will give you feedback as soon I tested the approach.

regards migro
regards
migro

User avatar
migro
Macro Veteran
Posts: 151
Joined: Thu Nov 06, 2003 5:23 pm
Location: Germany
Contact:

Re: How to write or edit multi-part string in the windows registry

Post by migro » Mon Nov 21, 2022 5:05 am

Hi together,

it works well when writing to HKEY_CURRENT_USER. When writing to HKEY_LOCAL_MACHINE it does not work.
I was logged in with local adminrights and even the compiled version executed as administrator does not make any difference.

Any ideas?

Thanks in advance
regards
migro

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts