Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    General and Desktop
    2
    8
    182
    Loading More Posts
    • 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.
    • InsaneZulol
      InsaneZulol last edited by 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?

      JonB 1 Reply Last reply Reply Quote 1
      • JonB
        JonB @InsaneZulol last edited by 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....

        InsaneZulol 1 Reply Last reply Reply Quote 1
        • JonB
          JonB @InsaneZulol last edited by

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

          InsaneZulol 1 Reply Last reply Reply Quote 2
          • InsaneZulol
            InsaneZulol @JonB last edited by

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

            JonB 1 Reply Last reply Reply Quote 1
            • JonB
              JonB @InsaneZulol last edited by

              @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 Reply Quote 0
              • InsaneZulol
                InsaneZulol last edited by

                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

                JonB 1 Reply Last reply Reply Quote 0
                • JonB
                  JonB @InsaneZulol last edited by 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....

                  InsaneZulol 1 Reply Last reply Reply Quote 1
                  • InsaneZulol
                    InsaneZulol @JonB last edited by 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.

                    JonB 1 Reply Last reply Reply Quote 1
                    • JonB
                      JonB @InsaneZulol last edited by

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

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post