Search code examples
registryjscript

Writing to Registry type REG_MULTI_SZ


I am trying to write to the Registry using Jscript. I am able to do this command for REG_SZ, but it doesn't support REG_MULTI_SZ.

How can I write to the Registry using Jscript when the Registry I am trying to change is of type REG_MULTI_SZ?

var WshShell = Wscript.CreateObject("Wscript.Shell");
var regPath = "HKLM\\SOFTWARE\\PROGRAM\\ProgramName";
var newVal = "com.settings=changed";
var regType = "REG_SZ";

WshShell.RegWrite (regPath, newVal, regType);

Solution

  • I did not end up using Penton.RegObject. but that link did send me to finding a solution.

    instead I did this to change the REG_MULTI_SZ:

            var objShell = new ActiveXObject("Shell.Application");
    
            var commandtoRun = "reg.exe "; //"C:\\Windows\\System32\\reg.exe ";
            var regPath = "HKLM\\SOFTWARE\\PROGRAM\\ProgramName";
            var newVal = "com.settings=changed\\0com.user=newUserName\\0";
    
            var args = "ADD \""+regPath + "\" /v Options /t REG_MULTI_SZ /d "+newVal;
    
            objShell.ShellExecute(commandtoRun,args);