Add environment variable as a startup argument (Windows)











up vote
0
down vote

favorite












Let's say I have a program called myProgram.exe. I create a shortcut and send it to my desktop.



Now I right-click shortcut, and go to properties. I add the argument "-ldir %cd%" to the target.



The problem is %cd% never evaluates, it goes into the program as "%cd% literally. Is it not possible to pass variables as arguments?










share|improve this question


























    up vote
    0
    down vote

    favorite












    Let's say I have a program called myProgram.exe. I create a shortcut and send it to my desktop.



    Now I right-click shortcut, and go to properties. I add the argument "-ldir %cd%" to the target.



    The problem is %cd% never evaluates, it goes into the program as "%cd% literally. Is it not possible to pass variables as arguments?










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Let's say I have a program called myProgram.exe. I create a shortcut and send it to my desktop.



      Now I right-click shortcut, and go to properties. I add the argument "-ldir %cd%" to the target.



      The problem is %cd% never evaluates, it goes into the program as "%cd% literally. Is it not possible to pass variables as arguments?










      share|improve this question













      Let's say I have a program called myProgram.exe. I create a shortcut and send it to my desktop.



      Now I right-click shortcut, and go to properties. I add the argument "-ldir %cd%" to the target.



      The problem is %cd% never evaluates, it goes into the program as "%cd% literally. Is it not possible to pass variables as arguments?







      environment-variables file-shortcut






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 at 14:50









      Joseph Kreifels II

      185




      185






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          It appears I am already doing things right. If I pass in %windir%, it works fine.



          I am assuming the variable CD is never set without the help of command prompt.



          I guess the only solution for my specific problem is to use a batch file instead of a .lnk (shortcut).



          EDIT: Solution



          I found that you could just start cmd.exe and pass the exe and arguments there.



          In the event users have spaces (I hate spaces), you should surround the entire argument for cmd.exe in double quotes as well as the individual items like so



          C:WindowsSystem32cmd.exe /c ""C:Users\Path To ExemyProgram.exe" -ldir "%cd%""



          See: https://ss64.com/nt/cmd.html






          share|improve this answer























          • C:WindowsSystem32cmd.exe /c "C:Users<USER><PathToExe>myProgram.exe" -ldir %cd% gets close, but doesn't work if user has a space in directory name, so it can't be a guarantee. Wrapping the %cd% in double quotes looks to crash the system or something
            – Joseph Kreifels II
            Nov 21 at 15:34










          • Solved. C:WindowsSystem32cmd.exe /c ""C:Users<USER><PathToExe>myProgram.exe" -ldir "%cd%"" See: ss64.com/nt/cmd.html
            – Joseph Kreifels II
            Nov 21 at 15:43











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1377308%2fadd-environment-variable-as-a-startup-argument-windows%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          It appears I am already doing things right. If I pass in %windir%, it works fine.



          I am assuming the variable CD is never set without the help of command prompt.



          I guess the only solution for my specific problem is to use a batch file instead of a .lnk (shortcut).



          EDIT: Solution



          I found that you could just start cmd.exe and pass the exe and arguments there.



          In the event users have spaces (I hate spaces), you should surround the entire argument for cmd.exe in double quotes as well as the individual items like so



          C:WindowsSystem32cmd.exe /c ""C:Users\Path To ExemyProgram.exe" -ldir "%cd%""



          See: https://ss64.com/nt/cmd.html






          share|improve this answer























          • C:WindowsSystem32cmd.exe /c "C:Users<USER><PathToExe>myProgram.exe" -ldir %cd% gets close, but doesn't work if user has a space in directory name, so it can't be a guarantee. Wrapping the %cd% in double quotes looks to crash the system or something
            – Joseph Kreifels II
            Nov 21 at 15:34










          • Solved. C:WindowsSystem32cmd.exe /c ""C:Users<USER><PathToExe>myProgram.exe" -ldir "%cd%"" See: ss64.com/nt/cmd.html
            – Joseph Kreifels II
            Nov 21 at 15:43















          up vote
          0
          down vote













          It appears I am already doing things right. If I pass in %windir%, it works fine.



          I am assuming the variable CD is never set without the help of command prompt.



          I guess the only solution for my specific problem is to use a batch file instead of a .lnk (shortcut).



          EDIT: Solution



          I found that you could just start cmd.exe and pass the exe and arguments there.



          In the event users have spaces (I hate spaces), you should surround the entire argument for cmd.exe in double quotes as well as the individual items like so



          C:WindowsSystem32cmd.exe /c ""C:Users\Path To ExemyProgram.exe" -ldir "%cd%""



          See: https://ss64.com/nt/cmd.html






          share|improve this answer























          • C:WindowsSystem32cmd.exe /c "C:Users<USER><PathToExe>myProgram.exe" -ldir %cd% gets close, but doesn't work if user has a space in directory name, so it can't be a guarantee. Wrapping the %cd% in double quotes looks to crash the system or something
            – Joseph Kreifels II
            Nov 21 at 15:34










          • Solved. C:WindowsSystem32cmd.exe /c ""C:Users<USER><PathToExe>myProgram.exe" -ldir "%cd%"" See: ss64.com/nt/cmd.html
            – Joseph Kreifels II
            Nov 21 at 15:43













          up vote
          0
          down vote










          up vote
          0
          down vote









          It appears I am already doing things right. If I pass in %windir%, it works fine.



          I am assuming the variable CD is never set without the help of command prompt.



          I guess the only solution for my specific problem is to use a batch file instead of a .lnk (shortcut).



          EDIT: Solution



          I found that you could just start cmd.exe and pass the exe and arguments there.



          In the event users have spaces (I hate spaces), you should surround the entire argument for cmd.exe in double quotes as well as the individual items like so



          C:WindowsSystem32cmd.exe /c ""C:Users\Path To ExemyProgram.exe" -ldir "%cd%""



          See: https://ss64.com/nt/cmd.html






          share|improve this answer














          It appears I am already doing things right. If I pass in %windir%, it works fine.



          I am assuming the variable CD is never set without the help of command prompt.



          I guess the only solution for my specific problem is to use a batch file instead of a .lnk (shortcut).



          EDIT: Solution



          I found that you could just start cmd.exe and pass the exe and arguments there.



          In the event users have spaces (I hate spaces), you should surround the entire argument for cmd.exe in double quotes as well as the individual items like so



          C:WindowsSystem32cmd.exe /c ""C:Users\Path To ExemyProgram.exe" -ldir "%cd%""



          See: https://ss64.com/nt/cmd.html







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 21 at 15:47

























          answered Nov 21 at 15:07









          Joseph Kreifels II

          185




          185












          • C:WindowsSystem32cmd.exe /c "C:Users<USER><PathToExe>myProgram.exe" -ldir %cd% gets close, but doesn't work if user has a space in directory name, so it can't be a guarantee. Wrapping the %cd% in double quotes looks to crash the system or something
            – Joseph Kreifels II
            Nov 21 at 15:34










          • Solved. C:WindowsSystem32cmd.exe /c ""C:Users<USER><PathToExe>myProgram.exe" -ldir "%cd%"" See: ss64.com/nt/cmd.html
            – Joseph Kreifels II
            Nov 21 at 15:43


















          • C:WindowsSystem32cmd.exe /c "C:Users<USER><PathToExe>myProgram.exe" -ldir %cd% gets close, but doesn't work if user has a space in directory name, so it can't be a guarantee. Wrapping the %cd% in double quotes looks to crash the system or something
            – Joseph Kreifels II
            Nov 21 at 15:34










          • Solved. C:WindowsSystem32cmd.exe /c ""C:Users<USER><PathToExe>myProgram.exe" -ldir "%cd%"" See: ss64.com/nt/cmd.html
            – Joseph Kreifels II
            Nov 21 at 15:43
















          C:WindowsSystem32cmd.exe /c "C:Users<USER><PathToExe>myProgram.exe" -ldir %cd% gets close, but doesn't work if user has a space in directory name, so it can't be a guarantee. Wrapping the %cd% in double quotes looks to crash the system or something
          – Joseph Kreifels II
          Nov 21 at 15:34




          C:WindowsSystem32cmd.exe /c "C:Users<USER><PathToExe>myProgram.exe" -ldir %cd% gets close, but doesn't work if user has a space in directory name, so it can't be a guarantee. Wrapping the %cd% in double quotes looks to crash the system or something
          – Joseph Kreifels II
          Nov 21 at 15:34












          Solved. C:WindowsSystem32cmd.exe /c ""C:Users<USER><PathToExe>myProgram.exe" -ldir "%cd%"" See: ss64.com/nt/cmd.html
          – Joseph Kreifels II
          Nov 21 at 15:43




          Solved. C:WindowsSystem32cmd.exe /c ""C:Users<USER><PathToExe>myProgram.exe" -ldir "%cd%"" See: ss64.com/nt/cmd.html
          – Joseph Kreifels II
          Nov 21 at 15:43


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Super User!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1377308%2fadd-environment-variable-as-a-startup-argument-windows%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          QoS: MAC-Priority for clients behind a repeater

          Ивакино (Тотемский район)

          Can't locate Autom4te/ChannelDefs.pm in @INC (when it definitely is there)