How to create a link to an executable which must be run in its own folder?












2















I have a program inside a folder like below. The objective is to have a link in the utilities folder so I can call it from any command line.




C:UtilitiesProgram
program.exe
some.important.dll
some.important.ini


Is it possible to create a link, symbolic link or hard link in the Utilities folder that can run the file as if its inside the Program folder? When I create the symlink, the program does not locate its dll/ini files. When I create a .lnk, I can't run it from command line by just typing "program", e.g. in PowerShell, cmd or Run.




C:Utilities
program <--------- should be the link



I need the link because my environment PATH will include only the Utilities folder, so I don't want to append a new folder to the PATH every time I add a new Program folder, I would like just to create a new [hard/sym]link.










share|improve this question























  • As you said, the problem is the program won't be able to find its config files or dependencies. Probably the best approach here is to use batch. For example C:Utilitiesprogram.bat with content @start "" /D "%~dp0Program" program.exe %*.

    – Vlastimil Ovčáčík
    Aug 16 '13 at 12:20











  • I'll keep the batch approach for the while, but one of the drawbacks is for example: I can't have the program output in the current terminal (cmd/Powershell). Suppose I want to call program --help to print its usage info - it will only flash a cmd window and will not display the usage.

    – natenho
    Aug 16 '13 at 12:44






  • 1





    how about @start "" /B /D "%~dp0Program" program.exe %*?

    – Vlastimil Ovčáčík
    Aug 17 '13 at 18:45













  • /B switch helps the output but still batch can't solve seamlessly, you know? I'm still believing that it must have a simple way to get it working.

    – natenho
    Aug 18 '13 at 1:54
















2















I have a program inside a folder like below. The objective is to have a link in the utilities folder so I can call it from any command line.




C:UtilitiesProgram
program.exe
some.important.dll
some.important.ini


Is it possible to create a link, symbolic link or hard link in the Utilities folder that can run the file as if its inside the Program folder? When I create the symlink, the program does not locate its dll/ini files. When I create a .lnk, I can't run it from command line by just typing "program", e.g. in PowerShell, cmd or Run.




C:Utilities
program <--------- should be the link



I need the link because my environment PATH will include only the Utilities folder, so I don't want to append a new folder to the PATH every time I add a new Program folder, I would like just to create a new [hard/sym]link.










share|improve this question























  • As you said, the problem is the program won't be able to find its config files or dependencies. Probably the best approach here is to use batch. For example C:Utilitiesprogram.bat with content @start "" /D "%~dp0Program" program.exe %*.

    – Vlastimil Ovčáčík
    Aug 16 '13 at 12:20











  • I'll keep the batch approach for the while, but one of the drawbacks is for example: I can't have the program output in the current terminal (cmd/Powershell). Suppose I want to call program --help to print its usage info - it will only flash a cmd window and will not display the usage.

    – natenho
    Aug 16 '13 at 12:44






  • 1





    how about @start "" /B /D "%~dp0Program" program.exe %*?

    – Vlastimil Ovčáčík
    Aug 17 '13 at 18:45













  • /B switch helps the output but still batch can't solve seamlessly, you know? I'm still believing that it must have a simple way to get it working.

    – natenho
    Aug 18 '13 at 1:54














2












2








2








I have a program inside a folder like below. The objective is to have a link in the utilities folder so I can call it from any command line.




C:UtilitiesProgram
program.exe
some.important.dll
some.important.ini


Is it possible to create a link, symbolic link or hard link in the Utilities folder that can run the file as if its inside the Program folder? When I create the symlink, the program does not locate its dll/ini files. When I create a .lnk, I can't run it from command line by just typing "program", e.g. in PowerShell, cmd or Run.




C:Utilities
program <--------- should be the link



I need the link because my environment PATH will include only the Utilities folder, so I don't want to append a new folder to the PATH every time I add a new Program folder, I would like just to create a new [hard/sym]link.










share|improve this question














I have a program inside a folder like below. The objective is to have a link in the utilities folder so I can call it from any command line.




C:UtilitiesProgram
program.exe
some.important.dll
some.important.ini


Is it possible to create a link, symbolic link or hard link in the Utilities folder that can run the file as if its inside the Program folder? When I create the symlink, the program does not locate its dll/ini files. When I create a .lnk, I can't run it from command line by just typing "program", e.g. in PowerShell, cmd or Run.




C:Utilities
program <--------- should be the link



I need the link because my environment PATH will include only the Utilities folder, so I don't want to append a new folder to the PATH every time I add a new Program folder, I would like just to create a new [hard/sym]link.







windows command-line symbolic-link






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 15 '13 at 22:13









natenhonatenho

13117




13117













  • As you said, the problem is the program won't be able to find its config files or dependencies. Probably the best approach here is to use batch. For example C:Utilitiesprogram.bat with content @start "" /D "%~dp0Program" program.exe %*.

    – Vlastimil Ovčáčík
    Aug 16 '13 at 12:20











  • I'll keep the batch approach for the while, but one of the drawbacks is for example: I can't have the program output in the current terminal (cmd/Powershell). Suppose I want to call program --help to print its usage info - it will only flash a cmd window and will not display the usage.

    – natenho
    Aug 16 '13 at 12:44






  • 1





    how about @start "" /B /D "%~dp0Program" program.exe %*?

    – Vlastimil Ovčáčík
    Aug 17 '13 at 18:45













  • /B switch helps the output but still batch can't solve seamlessly, you know? I'm still believing that it must have a simple way to get it working.

    – natenho
    Aug 18 '13 at 1:54



















  • As you said, the problem is the program won't be able to find its config files or dependencies. Probably the best approach here is to use batch. For example C:Utilitiesprogram.bat with content @start "" /D "%~dp0Program" program.exe %*.

    – Vlastimil Ovčáčík
    Aug 16 '13 at 12:20











  • I'll keep the batch approach for the while, but one of the drawbacks is for example: I can't have the program output in the current terminal (cmd/Powershell). Suppose I want to call program --help to print its usage info - it will only flash a cmd window and will not display the usage.

    – natenho
    Aug 16 '13 at 12:44






  • 1





    how about @start "" /B /D "%~dp0Program" program.exe %*?

    – Vlastimil Ovčáčík
    Aug 17 '13 at 18:45













  • /B switch helps the output but still batch can't solve seamlessly, you know? I'm still believing that it must have a simple way to get it working.

    – natenho
    Aug 18 '13 at 1:54

















As you said, the problem is the program won't be able to find its config files or dependencies. Probably the best approach here is to use batch. For example C:Utilitiesprogram.bat with content @start "" /D "%~dp0Program" program.exe %*.

– Vlastimil Ovčáčík
Aug 16 '13 at 12:20





As you said, the problem is the program won't be able to find its config files or dependencies. Probably the best approach here is to use batch. For example C:Utilitiesprogram.bat with content @start "" /D "%~dp0Program" program.exe %*.

– Vlastimil Ovčáčík
Aug 16 '13 at 12:20













I'll keep the batch approach for the while, but one of the drawbacks is for example: I can't have the program output in the current terminal (cmd/Powershell). Suppose I want to call program --help to print its usage info - it will only flash a cmd window and will not display the usage.

– natenho
Aug 16 '13 at 12:44





I'll keep the batch approach for the while, but one of the drawbacks is for example: I can't have the program output in the current terminal (cmd/Powershell). Suppose I want to call program --help to print its usage info - it will only flash a cmd window and will not display the usage.

– natenho
Aug 16 '13 at 12:44




1




1





how about @start "" /B /D "%~dp0Program" program.exe %*?

– Vlastimil Ovčáčík
Aug 17 '13 at 18:45







how about @start "" /B /D "%~dp0Program" program.exe %*?

– Vlastimil Ovčáčík
Aug 17 '13 at 18:45















/B switch helps the output but still batch can't solve seamlessly, you know? I'm still believing that it must have a simple way to get it working.

– natenho
Aug 18 '13 at 1:54





/B switch helps the output but still batch can't solve seamlessly, you know? I'm still believing that it must have a simple way to get it working.

– natenho
Aug 18 '13 at 1:54










4 Answers
4






active

oldest

votes


















0














If you create a shortcut there, you would then use the "start in" field in the shortcut to indicate the folder it should run in.



Then, just try start program.lnk and see if that works.






share|improve this answer



















  • 1





    Thanks, but when I create a .lnk, I can't run it from command line by just typing "program", the idea is to run it just like I run "notepad" or "calc" for instance, easy as that.

    – natenho
    Aug 15 '13 at 23:46











  • How about putting it into a batch file? Would that work?

    – Jack
    Aug 16 '13 at 13:18











  • You can notice the drawbacks of batch files approach in the other comments along the question.

    – natenho
    Aug 16 '13 at 13:35



















0














You could try an MS-Dos batch file, with the same filename (except for the extension) as the program you want to execute.



For example, C:UtilitesProgram.bat could contain something like:



C:UtilitiesProgramprogram.exe


or



@start "" /D "%~dp0Program" program.exe %*


Then, when you CD to C:Utilities, you simply type Program, and the original file you wanted to launch will be launched.



Or, you could program the exe file to be launched from anywhere using the DosKey feature. If you choose to do so, perhaps This article can help you learn to do so.



There's also the option of creating hard/symbolic links to all the other files in the original directory, in addition to the exe file.



You can also copy (or link) the program, and it's files, to your System32 directory. Like DosKey, the latter will allow you to launch the program from anywhere, even in CMD/Run/PowerShell (but not Explorer).






share|improve this answer


























  • Actually I do the batch alternative, but its not seamless as a simple link. And its not very confortable to have a fast cmd window popping up or flashing in taskbar. Regarding DOSKEY, I can't use it to run outside cmd, like in powershell or start->run, can I? You mentioned anywhere, but it seems doskey is a very old exclusive cmd/ms-dos feature.

    – natenho
    Aug 16 '13 at 0:33











  • Sorry, I didn't realize you mentioned using either the Run command, or PowerShell. I thought you were only doing this with the Command Prompt. I've expanded my original answer, providing two more options for you to choose from.

    – TSJNachos117
    Aug 16 '13 at 1:36













  • I appreciate your comments, but it seems worst than the batch approach to copy or to link several files - some programs has too many folders/files. I don't need system32 because Utilities is already in PATH environment variable.

    – natenho
    Aug 16 '13 at 11:31



















0














Unfortunately I cant comment to answers. So I have to write a new one.

If you want to use the comand to the program native in the commandline then dont use the command @Start.



@"pathtofile/program.exe" %*


With this all parameters are piped to the original program and all outputs are piped to the calling commandline. With an entry of the utility Directory in the path you can use it in cmd, powershell and run-dialog.

In this answere here, the technique is described, too.



PS: Just use .cmd instead of .bat to differentiate optically the shortcut from an normal batch file. The usage is the same.



EDIT: After testing I realized that the called programm does not recognizes needed files in the same folder (as wanted from the question opener). So a more complex script (all in batch) is needed to change to the programms folder, then execute und than changes dir back.



The only thing you have to change in the script is the progpath variable to the wanted program. Of course you can skip all the REM-commands too (only commenting the code).

Heres the script:



@ECHO OFF

REM enable local variables
SETLOCAL

REM fullpath of program
SET progpath=C:Dokumente und EinstellungenLukas SeidlerDesktopnotepad

REM save current direcory
SET currpath=%CD%

REM change to drive of prog
FOR %%I IN ("%progpath%") DO (%%~dI)

REM change to path of prog
FOR %%I IN ("%progpath%") DO (CD "%%~pI")

REM execute prog with optional parameters
FOR %%I IN ("%progpath%") DO ("%%~nxI" %*)

REM change to calling drive
FOR %%I IN ("%currpath%") DO (%%~dI)

REM change to calling path
FOR %%I IN ("%currpath%") DO (CD "%%~pnI")

REM disable local variables
ENDLOCAL

REM EOF


For easily creating the file in the utilities dir use another script and place it in the utilities dir (for easy access). I named it makeshortcut.bat. Usage is: makeshortcut "fullpathtofile". Just change the variable utilitypath to your folder.



@ECHO OFF
SETLOCAL
SET utilitypath=D:AppsCommonFiles
SET outfile="%utilitypath%%~n1.cmd"
ECHO @ECHO OFF > %outfile%
ECHO SETLOCAL >> %outfile%
ECHO SET progpath=%~f1 >> %outfile%
ECHO SET currpath=^%%CD^%% >> %outfile%
ECHO FOR ^%%^%%I IN ("^%%progpath^%%") DO (^%%^%%~dI) >> %outfile%
ECHO FOR ^%%^%%I IN ("^%%progpath^%%") DO (CD "^%%^%%~pI") >> %outfile%
ECHO FOR ^%%^%%I IN ("^%%progpath^%%") DO ("^%%^%%~nxI" ^%%*) >> %outfile%
ECHO FOR ^%%^%%I IN ("^%%currpath^%%") DO (^%%^%%~dI) >> %outfile%
ECHO FOR ^%%^%%I IN ("^%%currpath^%%") DO (CD "^%%^%%~pnI") >> %outfile%
ECHO ENDLOCAL >> %outfile%
ECHO done.


WARNING: No checks of arguments are made. Existing files are overwritten.






share|improve this answer

































    0














    This worked for me when I installed 7z program and wanted to use it in command prompt:




    • I installed 7z, then I created a link to the exe file and copied it to windowssystem32 folder.

    • I created a 7z.bat file and put one line inside it : 7z.exe.lnk, and copied that file into the windowssystem32 folder.


    It then works as you wanted.
    Here is an example (sorry for the Danish windows):



    enter image description here






    share|improve this answer























      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',
      autoActivateHeartbeat: false,
      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%2f632487%2fhow-to-create-a-link-to-an-executable-which-must-be-run-in-its-own-folder%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      If you create a shortcut there, you would then use the "start in" field in the shortcut to indicate the folder it should run in.



      Then, just try start program.lnk and see if that works.






      share|improve this answer



















      • 1





        Thanks, but when I create a .lnk, I can't run it from command line by just typing "program", the idea is to run it just like I run "notepad" or "calc" for instance, easy as that.

        – natenho
        Aug 15 '13 at 23:46











      • How about putting it into a batch file? Would that work?

        – Jack
        Aug 16 '13 at 13:18











      • You can notice the drawbacks of batch files approach in the other comments along the question.

        – natenho
        Aug 16 '13 at 13:35
















      0














      If you create a shortcut there, you would then use the "start in" field in the shortcut to indicate the folder it should run in.



      Then, just try start program.lnk and see if that works.






      share|improve this answer



















      • 1





        Thanks, but when I create a .lnk, I can't run it from command line by just typing "program", the idea is to run it just like I run "notepad" or "calc" for instance, easy as that.

        – natenho
        Aug 15 '13 at 23:46











      • How about putting it into a batch file? Would that work?

        – Jack
        Aug 16 '13 at 13:18











      • You can notice the drawbacks of batch files approach in the other comments along the question.

        – natenho
        Aug 16 '13 at 13:35














      0












      0








      0







      If you create a shortcut there, you would then use the "start in" field in the shortcut to indicate the folder it should run in.



      Then, just try start program.lnk and see if that works.






      share|improve this answer













      If you create a shortcut there, you would then use the "start in" field in the shortcut to indicate the folder it should run in.



      Then, just try start program.lnk and see if that works.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Aug 15 '13 at 23:31









      JackJack

      1,05767




      1,05767








      • 1





        Thanks, but when I create a .lnk, I can't run it from command line by just typing "program", the idea is to run it just like I run "notepad" or "calc" for instance, easy as that.

        – natenho
        Aug 15 '13 at 23:46











      • How about putting it into a batch file? Would that work?

        – Jack
        Aug 16 '13 at 13:18











      • You can notice the drawbacks of batch files approach in the other comments along the question.

        – natenho
        Aug 16 '13 at 13:35














      • 1





        Thanks, but when I create a .lnk, I can't run it from command line by just typing "program", the idea is to run it just like I run "notepad" or "calc" for instance, easy as that.

        – natenho
        Aug 15 '13 at 23:46











      • How about putting it into a batch file? Would that work?

        – Jack
        Aug 16 '13 at 13:18











      • You can notice the drawbacks of batch files approach in the other comments along the question.

        – natenho
        Aug 16 '13 at 13:35








      1




      1





      Thanks, but when I create a .lnk, I can't run it from command line by just typing "program", the idea is to run it just like I run "notepad" or "calc" for instance, easy as that.

      – natenho
      Aug 15 '13 at 23:46





      Thanks, but when I create a .lnk, I can't run it from command line by just typing "program", the idea is to run it just like I run "notepad" or "calc" for instance, easy as that.

      – natenho
      Aug 15 '13 at 23:46













      How about putting it into a batch file? Would that work?

      – Jack
      Aug 16 '13 at 13:18





      How about putting it into a batch file? Would that work?

      – Jack
      Aug 16 '13 at 13:18













      You can notice the drawbacks of batch files approach in the other comments along the question.

      – natenho
      Aug 16 '13 at 13:35





      You can notice the drawbacks of batch files approach in the other comments along the question.

      – natenho
      Aug 16 '13 at 13:35













      0














      You could try an MS-Dos batch file, with the same filename (except for the extension) as the program you want to execute.



      For example, C:UtilitesProgram.bat could contain something like:



      C:UtilitiesProgramprogram.exe


      or



      @start "" /D "%~dp0Program" program.exe %*


      Then, when you CD to C:Utilities, you simply type Program, and the original file you wanted to launch will be launched.



      Or, you could program the exe file to be launched from anywhere using the DosKey feature. If you choose to do so, perhaps This article can help you learn to do so.



      There's also the option of creating hard/symbolic links to all the other files in the original directory, in addition to the exe file.



      You can also copy (or link) the program, and it's files, to your System32 directory. Like DosKey, the latter will allow you to launch the program from anywhere, even in CMD/Run/PowerShell (but not Explorer).






      share|improve this answer


























      • Actually I do the batch alternative, but its not seamless as a simple link. And its not very confortable to have a fast cmd window popping up or flashing in taskbar. Regarding DOSKEY, I can't use it to run outside cmd, like in powershell or start->run, can I? You mentioned anywhere, but it seems doskey is a very old exclusive cmd/ms-dos feature.

        – natenho
        Aug 16 '13 at 0:33











      • Sorry, I didn't realize you mentioned using either the Run command, or PowerShell. I thought you were only doing this with the Command Prompt. I've expanded my original answer, providing two more options for you to choose from.

        – TSJNachos117
        Aug 16 '13 at 1:36













      • I appreciate your comments, but it seems worst than the batch approach to copy or to link several files - some programs has too many folders/files. I don't need system32 because Utilities is already in PATH environment variable.

        – natenho
        Aug 16 '13 at 11:31
















      0














      You could try an MS-Dos batch file, with the same filename (except for the extension) as the program you want to execute.



      For example, C:UtilitesProgram.bat could contain something like:



      C:UtilitiesProgramprogram.exe


      or



      @start "" /D "%~dp0Program" program.exe %*


      Then, when you CD to C:Utilities, you simply type Program, and the original file you wanted to launch will be launched.



      Or, you could program the exe file to be launched from anywhere using the DosKey feature. If you choose to do so, perhaps This article can help you learn to do so.



      There's also the option of creating hard/symbolic links to all the other files in the original directory, in addition to the exe file.



      You can also copy (or link) the program, and it's files, to your System32 directory. Like DosKey, the latter will allow you to launch the program from anywhere, even in CMD/Run/PowerShell (but not Explorer).






      share|improve this answer


























      • Actually I do the batch alternative, but its not seamless as a simple link. And its not very confortable to have a fast cmd window popping up or flashing in taskbar. Regarding DOSKEY, I can't use it to run outside cmd, like in powershell or start->run, can I? You mentioned anywhere, but it seems doskey is a very old exclusive cmd/ms-dos feature.

        – natenho
        Aug 16 '13 at 0:33











      • Sorry, I didn't realize you mentioned using either the Run command, or PowerShell. I thought you were only doing this with the Command Prompt. I've expanded my original answer, providing two more options for you to choose from.

        – TSJNachos117
        Aug 16 '13 at 1:36













      • I appreciate your comments, but it seems worst than the batch approach to copy or to link several files - some programs has too many folders/files. I don't need system32 because Utilities is already in PATH environment variable.

        – natenho
        Aug 16 '13 at 11:31














      0












      0








      0







      You could try an MS-Dos batch file, with the same filename (except for the extension) as the program you want to execute.



      For example, C:UtilitesProgram.bat could contain something like:



      C:UtilitiesProgramprogram.exe


      or



      @start "" /D "%~dp0Program" program.exe %*


      Then, when you CD to C:Utilities, you simply type Program, and the original file you wanted to launch will be launched.



      Or, you could program the exe file to be launched from anywhere using the DosKey feature. If you choose to do so, perhaps This article can help you learn to do so.



      There's also the option of creating hard/symbolic links to all the other files in the original directory, in addition to the exe file.



      You can also copy (or link) the program, and it's files, to your System32 directory. Like DosKey, the latter will allow you to launch the program from anywhere, even in CMD/Run/PowerShell (but not Explorer).






      share|improve this answer















      You could try an MS-Dos batch file, with the same filename (except for the extension) as the program you want to execute.



      For example, C:UtilitesProgram.bat could contain something like:



      C:UtilitiesProgramprogram.exe


      or



      @start "" /D "%~dp0Program" program.exe %*


      Then, when you CD to C:Utilities, you simply type Program, and the original file you wanted to launch will be launched.



      Or, you could program the exe file to be launched from anywhere using the DosKey feature. If you choose to do so, perhaps This article can help you learn to do so.



      There's also the option of creating hard/symbolic links to all the other files in the original directory, in addition to the exe file.



      You can also copy (or link) the program, and it's files, to your System32 directory. Like DosKey, the latter will allow you to launch the program from anywhere, even in CMD/Run/PowerShell (but not Explorer).







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Aug 16 '13 at 12:33









      Jawa

      3,15982435




      3,15982435










      answered Aug 16 '13 at 0:12









      TSJNachos117TSJNachos117

      25639




      25639













      • Actually I do the batch alternative, but its not seamless as a simple link. And its not very confortable to have a fast cmd window popping up or flashing in taskbar. Regarding DOSKEY, I can't use it to run outside cmd, like in powershell or start->run, can I? You mentioned anywhere, but it seems doskey is a very old exclusive cmd/ms-dos feature.

        – natenho
        Aug 16 '13 at 0:33











      • Sorry, I didn't realize you mentioned using either the Run command, or PowerShell. I thought you were only doing this with the Command Prompt. I've expanded my original answer, providing two more options for you to choose from.

        – TSJNachos117
        Aug 16 '13 at 1:36













      • I appreciate your comments, but it seems worst than the batch approach to copy or to link several files - some programs has too many folders/files. I don't need system32 because Utilities is already in PATH environment variable.

        – natenho
        Aug 16 '13 at 11:31



















      • Actually I do the batch alternative, but its not seamless as a simple link. And its not very confortable to have a fast cmd window popping up or flashing in taskbar. Regarding DOSKEY, I can't use it to run outside cmd, like in powershell or start->run, can I? You mentioned anywhere, but it seems doskey is a very old exclusive cmd/ms-dos feature.

        – natenho
        Aug 16 '13 at 0:33











      • Sorry, I didn't realize you mentioned using either the Run command, or PowerShell. I thought you were only doing this with the Command Prompt. I've expanded my original answer, providing two more options for you to choose from.

        – TSJNachos117
        Aug 16 '13 at 1:36













      • I appreciate your comments, but it seems worst than the batch approach to copy or to link several files - some programs has too many folders/files. I don't need system32 because Utilities is already in PATH environment variable.

        – natenho
        Aug 16 '13 at 11:31

















      Actually I do the batch alternative, but its not seamless as a simple link. And its not very confortable to have a fast cmd window popping up or flashing in taskbar. Regarding DOSKEY, I can't use it to run outside cmd, like in powershell or start->run, can I? You mentioned anywhere, but it seems doskey is a very old exclusive cmd/ms-dos feature.

      – natenho
      Aug 16 '13 at 0:33





      Actually I do the batch alternative, but its not seamless as a simple link. And its not very confortable to have a fast cmd window popping up or flashing in taskbar. Regarding DOSKEY, I can't use it to run outside cmd, like in powershell or start->run, can I? You mentioned anywhere, but it seems doskey is a very old exclusive cmd/ms-dos feature.

      – natenho
      Aug 16 '13 at 0:33













      Sorry, I didn't realize you mentioned using either the Run command, or PowerShell. I thought you were only doing this with the Command Prompt. I've expanded my original answer, providing two more options for you to choose from.

      – TSJNachos117
      Aug 16 '13 at 1:36







      Sorry, I didn't realize you mentioned using either the Run command, or PowerShell. I thought you were only doing this with the Command Prompt. I've expanded my original answer, providing two more options for you to choose from.

      – TSJNachos117
      Aug 16 '13 at 1:36















      I appreciate your comments, but it seems worst than the batch approach to copy or to link several files - some programs has too many folders/files. I don't need system32 because Utilities is already in PATH environment variable.

      – natenho
      Aug 16 '13 at 11:31





      I appreciate your comments, but it seems worst than the batch approach to copy or to link several files - some programs has too many folders/files. I don't need system32 because Utilities is already in PATH environment variable.

      – natenho
      Aug 16 '13 at 11:31











      0














      Unfortunately I cant comment to answers. So I have to write a new one.

      If you want to use the comand to the program native in the commandline then dont use the command @Start.



      @"pathtofile/program.exe" %*


      With this all parameters are piped to the original program and all outputs are piped to the calling commandline. With an entry of the utility Directory in the path you can use it in cmd, powershell and run-dialog.

      In this answere here, the technique is described, too.



      PS: Just use .cmd instead of .bat to differentiate optically the shortcut from an normal batch file. The usage is the same.



      EDIT: After testing I realized that the called programm does not recognizes needed files in the same folder (as wanted from the question opener). So a more complex script (all in batch) is needed to change to the programms folder, then execute und than changes dir back.



      The only thing you have to change in the script is the progpath variable to the wanted program. Of course you can skip all the REM-commands too (only commenting the code).

      Heres the script:



      @ECHO OFF

      REM enable local variables
      SETLOCAL

      REM fullpath of program
      SET progpath=C:Dokumente und EinstellungenLukas SeidlerDesktopnotepad

      REM save current direcory
      SET currpath=%CD%

      REM change to drive of prog
      FOR %%I IN ("%progpath%") DO (%%~dI)

      REM change to path of prog
      FOR %%I IN ("%progpath%") DO (CD "%%~pI")

      REM execute prog with optional parameters
      FOR %%I IN ("%progpath%") DO ("%%~nxI" %*)

      REM change to calling drive
      FOR %%I IN ("%currpath%") DO (%%~dI)

      REM change to calling path
      FOR %%I IN ("%currpath%") DO (CD "%%~pnI")

      REM disable local variables
      ENDLOCAL

      REM EOF


      For easily creating the file in the utilities dir use another script and place it in the utilities dir (for easy access). I named it makeshortcut.bat. Usage is: makeshortcut "fullpathtofile". Just change the variable utilitypath to your folder.



      @ECHO OFF
      SETLOCAL
      SET utilitypath=D:AppsCommonFiles
      SET outfile="%utilitypath%%~n1.cmd"
      ECHO @ECHO OFF > %outfile%
      ECHO SETLOCAL >> %outfile%
      ECHO SET progpath=%~f1 >> %outfile%
      ECHO SET currpath=^%%CD^%% >> %outfile%
      ECHO FOR ^%%^%%I IN ("^%%progpath^%%") DO (^%%^%%~dI) >> %outfile%
      ECHO FOR ^%%^%%I IN ("^%%progpath^%%") DO (CD "^%%^%%~pI") >> %outfile%
      ECHO FOR ^%%^%%I IN ("^%%progpath^%%") DO ("^%%^%%~nxI" ^%%*) >> %outfile%
      ECHO FOR ^%%^%%I IN ("^%%currpath^%%") DO (^%%^%%~dI) >> %outfile%
      ECHO FOR ^%%^%%I IN ("^%%currpath^%%") DO (CD "^%%^%%~pnI") >> %outfile%
      ECHO ENDLOCAL >> %outfile%
      ECHO done.


      WARNING: No checks of arguments are made. Existing files are overwritten.






      share|improve this answer






























        0














        Unfortunately I cant comment to answers. So I have to write a new one.

        If you want to use the comand to the program native in the commandline then dont use the command @Start.



        @"pathtofile/program.exe" %*


        With this all parameters are piped to the original program and all outputs are piped to the calling commandline. With an entry of the utility Directory in the path you can use it in cmd, powershell and run-dialog.

        In this answere here, the technique is described, too.



        PS: Just use .cmd instead of .bat to differentiate optically the shortcut from an normal batch file. The usage is the same.



        EDIT: After testing I realized that the called programm does not recognizes needed files in the same folder (as wanted from the question opener). So a more complex script (all in batch) is needed to change to the programms folder, then execute und than changes dir back.



        The only thing you have to change in the script is the progpath variable to the wanted program. Of course you can skip all the REM-commands too (only commenting the code).

        Heres the script:



        @ECHO OFF

        REM enable local variables
        SETLOCAL

        REM fullpath of program
        SET progpath=C:Dokumente und EinstellungenLukas SeidlerDesktopnotepad

        REM save current direcory
        SET currpath=%CD%

        REM change to drive of prog
        FOR %%I IN ("%progpath%") DO (%%~dI)

        REM change to path of prog
        FOR %%I IN ("%progpath%") DO (CD "%%~pI")

        REM execute prog with optional parameters
        FOR %%I IN ("%progpath%") DO ("%%~nxI" %*)

        REM change to calling drive
        FOR %%I IN ("%currpath%") DO (%%~dI)

        REM change to calling path
        FOR %%I IN ("%currpath%") DO (CD "%%~pnI")

        REM disable local variables
        ENDLOCAL

        REM EOF


        For easily creating the file in the utilities dir use another script and place it in the utilities dir (for easy access). I named it makeshortcut.bat. Usage is: makeshortcut "fullpathtofile". Just change the variable utilitypath to your folder.



        @ECHO OFF
        SETLOCAL
        SET utilitypath=D:AppsCommonFiles
        SET outfile="%utilitypath%%~n1.cmd"
        ECHO @ECHO OFF > %outfile%
        ECHO SETLOCAL >> %outfile%
        ECHO SET progpath=%~f1 >> %outfile%
        ECHO SET currpath=^%%CD^%% >> %outfile%
        ECHO FOR ^%%^%%I IN ("^%%progpath^%%") DO (^%%^%%~dI) >> %outfile%
        ECHO FOR ^%%^%%I IN ("^%%progpath^%%") DO (CD "^%%^%%~pI") >> %outfile%
        ECHO FOR ^%%^%%I IN ("^%%progpath^%%") DO ("^%%^%%~nxI" ^%%*) >> %outfile%
        ECHO FOR ^%%^%%I IN ("^%%currpath^%%") DO (^%%^%%~dI) >> %outfile%
        ECHO FOR ^%%^%%I IN ("^%%currpath^%%") DO (CD "^%%^%%~pnI") >> %outfile%
        ECHO ENDLOCAL >> %outfile%
        ECHO done.


        WARNING: No checks of arguments are made. Existing files are overwritten.






        share|improve this answer




























          0












          0








          0







          Unfortunately I cant comment to answers. So I have to write a new one.

          If you want to use the comand to the program native in the commandline then dont use the command @Start.



          @"pathtofile/program.exe" %*


          With this all parameters are piped to the original program and all outputs are piped to the calling commandline. With an entry of the utility Directory in the path you can use it in cmd, powershell and run-dialog.

          In this answere here, the technique is described, too.



          PS: Just use .cmd instead of .bat to differentiate optically the shortcut from an normal batch file. The usage is the same.



          EDIT: After testing I realized that the called programm does not recognizes needed files in the same folder (as wanted from the question opener). So a more complex script (all in batch) is needed to change to the programms folder, then execute und than changes dir back.



          The only thing you have to change in the script is the progpath variable to the wanted program. Of course you can skip all the REM-commands too (only commenting the code).

          Heres the script:



          @ECHO OFF

          REM enable local variables
          SETLOCAL

          REM fullpath of program
          SET progpath=C:Dokumente und EinstellungenLukas SeidlerDesktopnotepad

          REM save current direcory
          SET currpath=%CD%

          REM change to drive of prog
          FOR %%I IN ("%progpath%") DO (%%~dI)

          REM change to path of prog
          FOR %%I IN ("%progpath%") DO (CD "%%~pI")

          REM execute prog with optional parameters
          FOR %%I IN ("%progpath%") DO ("%%~nxI" %*)

          REM change to calling drive
          FOR %%I IN ("%currpath%") DO (%%~dI)

          REM change to calling path
          FOR %%I IN ("%currpath%") DO (CD "%%~pnI")

          REM disable local variables
          ENDLOCAL

          REM EOF


          For easily creating the file in the utilities dir use another script and place it in the utilities dir (for easy access). I named it makeshortcut.bat. Usage is: makeshortcut "fullpathtofile". Just change the variable utilitypath to your folder.



          @ECHO OFF
          SETLOCAL
          SET utilitypath=D:AppsCommonFiles
          SET outfile="%utilitypath%%~n1.cmd"
          ECHO @ECHO OFF > %outfile%
          ECHO SETLOCAL >> %outfile%
          ECHO SET progpath=%~f1 >> %outfile%
          ECHO SET currpath=^%%CD^%% >> %outfile%
          ECHO FOR ^%%^%%I IN ("^%%progpath^%%") DO (^%%^%%~dI) >> %outfile%
          ECHO FOR ^%%^%%I IN ("^%%progpath^%%") DO (CD "^%%^%%~pI") >> %outfile%
          ECHO FOR ^%%^%%I IN ("^%%progpath^%%") DO ("^%%^%%~nxI" ^%%*) >> %outfile%
          ECHO FOR ^%%^%%I IN ("^%%currpath^%%") DO (^%%^%%~dI) >> %outfile%
          ECHO FOR ^%%^%%I IN ("^%%currpath^%%") DO (CD "^%%^%%~pnI") >> %outfile%
          ECHO ENDLOCAL >> %outfile%
          ECHO done.


          WARNING: No checks of arguments are made. Existing files are overwritten.






          share|improve this answer















          Unfortunately I cant comment to answers. So I have to write a new one.

          If you want to use the comand to the program native in the commandline then dont use the command @Start.



          @"pathtofile/program.exe" %*


          With this all parameters are piped to the original program and all outputs are piped to the calling commandline. With an entry of the utility Directory in the path you can use it in cmd, powershell and run-dialog.

          In this answere here, the technique is described, too.



          PS: Just use .cmd instead of .bat to differentiate optically the shortcut from an normal batch file. The usage is the same.



          EDIT: After testing I realized that the called programm does not recognizes needed files in the same folder (as wanted from the question opener). So a more complex script (all in batch) is needed to change to the programms folder, then execute und than changes dir back.



          The only thing you have to change in the script is the progpath variable to the wanted program. Of course you can skip all the REM-commands too (only commenting the code).

          Heres the script:



          @ECHO OFF

          REM enable local variables
          SETLOCAL

          REM fullpath of program
          SET progpath=C:Dokumente und EinstellungenLukas SeidlerDesktopnotepad

          REM save current direcory
          SET currpath=%CD%

          REM change to drive of prog
          FOR %%I IN ("%progpath%") DO (%%~dI)

          REM change to path of prog
          FOR %%I IN ("%progpath%") DO (CD "%%~pI")

          REM execute prog with optional parameters
          FOR %%I IN ("%progpath%") DO ("%%~nxI" %*)

          REM change to calling drive
          FOR %%I IN ("%currpath%") DO (%%~dI)

          REM change to calling path
          FOR %%I IN ("%currpath%") DO (CD "%%~pnI")

          REM disable local variables
          ENDLOCAL

          REM EOF


          For easily creating the file in the utilities dir use another script and place it in the utilities dir (for easy access). I named it makeshortcut.bat. Usage is: makeshortcut "fullpathtofile". Just change the variable utilitypath to your folder.



          @ECHO OFF
          SETLOCAL
          SET utilitypath=D:AppsCommonFiles
          SET outfile="%utilitypath%%~n1.cmd"
          ECHO @ECHO OFF > %outfile%
          ECHO SETLOCAL >> %outfile%
          ECHO SET progpath=%~f1 >> %outfile%
          ECHO SET currpath=^%%CD^%% >> %outfile%
          ECHO FOR ^%%^%%I IN ("^%%progpath^%%") DO (^%%^%%~dI) >> %outfile%
          ECHO FOR ^%%^%%I IN ("^%%progpath^%%") DO (CD "^%%^%%~pI") >> %outfile%
          ECHO FOR ^%%^%%I IN ("^%%progpath^%%") DO ("^%%^%%~nxI" ^%%*) >> %outfile%
          ECHO FOR ^%%^%%I IN ("^%%currpath^%%") DO (^%%^%%~dI) >> %outfile%
          ECHO FOR ^%%^%%I IN ("^%%currpath^%%") DO (CD "^%%^%%~pnI") >> %outfile%
          ECHO ENDLOCAL >> %outfile%
          ECHO done.


          WARNING: No checks of arguments are made. Existing files are overwritten.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 20 '17 at 10:17









          Community

          1




          1










          answered Nov 16 '13 at 20:10









          RoKi0815RoKi0815

          417




          417























              0














              This worked for me when I installed 7z program and wanted to use it in command prompt:




              • I installed 7z, then I created a link to the exe file and copied it to windowssystem32 folder.

              • I created a 7z.bat file and put one line inside it : 7z.exe.lnk, and copied that file into the windowssystem32 folder.


              It then works as you wanted.
              Here is an example (sorry for the Danish windows):



              enter image description here






              share|improve this answer




























                0














                This worked for me when I installed 7z program and wanted to use it in command prompt:




                • I installed 7z, then I created a link to the exe file and copied it to windowssystem32 folder.

                • I created a 7z.bat file and put one line inside it : 7z.exe.lnk, and copied that file into the windowssystem32 folder.


                It then works as you wanted.
                Here is an example (sorry for the Danish windows):



                enter image description here






                share|improve this answer


























                  0












                  0








                  0







                  This worked for me when I installed 7z program and wanted to use it in command prompt:




                  • I installed 7z, then I created a link to the exe file and copied it to windowssystem32 folder.

                  • I created a 7z.bat file and put one line inside it : 7z.exe.lnk, and copied that file into the windowssystem32 folder.


                  It then works as you wanted.
                  Here is an example (sorry for the Danish windows):



                  enter image description here






                  share|improve this answer













                  This worked for me when I installed 7z program and wanted to use it in command prompt:




                  • I installed 7z, then I created a link to the exe file and copied it to windowssystem32 folder.

                  • I created a 7z.bat file and put one line inside it : 7z.exe.lnk, and copied that file into the windowssystem32 folder.


                  It then works as you wanted.
                  Here is an example (sorry for the Danish windows):



                  enter image description here







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 22 at 6:31









                  serupserup

                  1114




                  1114






























                      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.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f632487%2fhow-to-create-a-link-to-an-executable-which-must-be-run-in-its-own-folder%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

                      Plaza Victoria

                      In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

                      How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...