Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. addOperation.Execute("cmd") results in an ERROR: Invalid syntax.
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 598 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • InsaneZulolI Offline
    InsaneZulolI Offline
    InsaneZulol
    wrote on last edited by InsaneZulol
    #1

    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 err

    This is the result of running the installer with -v argument: 1bcb3d40-060d-42ea-b11b-a89219f35a41-image.png

    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?

    JonBJ 1 Reply Last reply
    1
    • InsaneZulolI InsaneZulol

      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

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #6

      @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....

      InsaneZulolI 1 Reply Last reply
      1
      • InsaneZulolI InsaneZulol

        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 err

        This is the result of running the installer with -v argument: 1bcb3d40-060d-42ea-b11b-a89219f35a41-image.png

        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?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #2

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

        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.

        InsaneZulolI 1 Reply Last reply
        2
        • JonBJ JonB

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

          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.

          InsaneZulolI Offline
          InsaneZulolI Offline
          InsaneZulol
          wrote on last edited by
          #3

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

          JonBJ 1 Reply Last reply
          1
          • InsaneZulolI InsaneZulol

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

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #4

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

            1 Reply Last reply
            0
            • InsaneZulolI Offline
              InsaneZulolI Offline
              InsaneZulol
              wrote on last edited by
              #5

              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

              JonBJ 1 Reply Last reply
              0
              • InsaneZulolI InsaneZulol

                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

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #6

                @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....

                InsaneZulolI 1 Reply Last reply
                1
                • JonBJ JonB

                  @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....

                  InsaneZulolI Offline
                  InsaneZulolI Offline
                  InsaneZulol
                  wrote on last edited by InsaneZulol
                  #7

                  @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.

                  JonBJ 1 Reply Last reply
                  1
                  • InsaneZulolI InsaneZulol

                    @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.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #8

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

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved