addOperation.Execute("cmd") results in an ERROR: Invalid syntax.

• I have a simple script where I just want to add a registry value to windows registry during installation.

function Component() {
if (installer.isInstaller())
installer.setValue("AllUsers", true);
}

Component.prototype.createOperations = function() {

try {
var manif = "reg add HKCU\\Software\\Google\\Chrome\\NativeMessagingHosts\\io.alan_kaluza.interlope /ve /t REG_SZ /d @TargetDir@\native_messaging_hosts.json /f";
var manifdel = "reg delete HKCU\\Software\\Google\\Chrome\\NativeMessagingHosts\\io.alan_kaluza.interlope /f"

// call the base create operations function
component.createOperations();
if (installer.value("os") === "win") {
component.addElevatedOperation("Execute", "cmd", "/C", manif, "UNDOEXECUTE", "cmd", "/C", manifdel);
}
} catch (e) {
print(e);
}
}



But unfortunately an error pops up during installation

This is the result of running the installer with -v argument:

gist

So... invalid syntax, but if I execute similiar command

reg add HKCU\Software\Google\Chrome\NativeMessagingHosts\io.alan_kaluza.interlope /ve /t REG_SZ /d C:\path\to\m\ /f


in console, it works:

Any clue why is that an invalid syntax?

• @InsaneZulol
Looking back at your screenshot, I admit I cannot see what I thought I saw yesterday about a mix of \\s and \s within one command, sorry about that.

I admit I know nothing about the installer, but why do you need/want to use cmd /c for your commands? Why can't you execute reg directly (breaking the line into separate arguments if required)? Then you could have e.g.

    var manif = "reg add HKCU\\Software\\Google\\Chrome\\NativeMessagingHosts\\io.alan_kaluza.interlope /ve /t REG_SZ /d \"@TargetDir@\native_messaging_hosts.json\" /f";


(I have "-quoted the path name which may contain spaces/parentheses.)

Even if you stick with cmd, I think if you read the SO link carefully (https://stackoverflow.com/a/43172047/489865) you'll see you can do it with "s instead of ^s, which is going to make it much easier here....

• var manif = "reg add HKCU\\Software\\Google\\Chrome\\NativeMessagingHosts\\io.alan_kaluza.interlope /ve /t REG_SZ /d @TargetDir@\native_messaging_hosts.json /f";

@TargetDir@\n is wrong, that's a newline! @TargetDir@\\n. Check your other backslahes.

• @JonB
Unfortunately, still "invalid syntax"
gist :(

• @InsaneZulol
Look at the error message and count the backslashes. You'll see you have the wrong number. Track it down.

• The ammount of backslashes is correct. I found the issue:
The /C has issues when it meets parentheses. And as I attempted to install in Program Files (x86)... yeah.
https://stackoverflow.com/questions/43171791/how-to-execute-a-cmd-c-command-with-round-bracket-in-the-path-name

Now I need to figure out how to get
@TargetDir@ return value as i.e. "Program Files ^(x86^)\app

• @InsaneZulol
Looking back at your screenshot, I admit I cannot see what I thought I saw yesterday about a mix of \\s and \s within one command, sorry about that.

I admit I know nothing about the installer, but why do you need/want to use cmd /c for your commands? Why can't you execute reg directly (breaking the line into separate arguments if required)? Then you could have e.g.

    var manif = "reg add HKCU\\Software\\Google\\Chrome\\NativeMessagingHosts\\io.alan_kaluza.interlope /ve /t REG_SZ /d \"@TargetDir@\native_messaging_hosts.json\" /f";


(I have "-quoted the path name which may contain spaces/parentheses.)

Even if you stick with cmd, I think if you read the SO link carefully (https://stackoverflow.com/a/43172047/489865) you'll see you can do it with "s instead of ^s, which is going to make it much easier here....

• @JonB
No need to apologize. It's confusing to read pathnames with multiple \\.
Thanks to your advice to get rid of cmd /c I tried this approach once again to see if it's possible - in a little different manner than I did at the beginning.

So to all future googlers searching for 'qt installer how to execute registry command with path as value'

        var reg_add = ["reg", "add", "HKCU\\Software\\Google\\Chrome\\NativeMessagingHosts\\io.alan_kaluza.interlope",
"/ve", "/t", "REG_SZ", "/d", "@TargetDir@\\native_messaging_manifest.json", "/f"];
var reg_del = ["reg", "delete", "HKCU\\Software\\Google\\Chrome\\NativeMessagingHosts\\io.alan_kaluza.interlope", "/f"];

component.createOperations();
if (installer.value("os") === "win") {
component.addOperation("Execute", reg_add, "UNDOEXECUTE", reg_del);
}


Finally did the trick for me.

• @InsaneZulol
Yes, to me this is a better way to do it :)