I made a game and I put all my code and executable in the code folder. I created a shortcut to the executable outside the folder so users won't have to dig in the folder to find the exe. Problem is the shortcut file path only works for me.

I uploaded the project to GitHub, so my file path starts from the downloads folder. So for my shortcut properties I tried

"%userprofile%\Downloads\Space-Invaders-main\Code\Space Invaders.exe" for target and

%userprofile%\Downloads\Space-Invaders-main\Code for start in.

My friend tried it, but he got this error.

How can I make a file path so any user from any computer can run the shortcut?

  • 3
    You can’t because you don’t know where they will put the executable files. This kind of thing is done with an installer. Jun 13, 2021 at 21:50
  • Or, are you saying you have a shortcut in a top level folder code that executed a file in a sub folder? In that case, use a relative path. Not an absolute path. The executable you are running is “relative” to the code folder. You don’t have to know where the code folder is, you just need to know where the executable is in relation to the code folder. If you’re in the code folder, where the shortcut is, then the shortcut should point to <subfolder>\<subfolder>\game.exe Jun 13, 2021 at 21:53
  • 1
    Create a folder and shortcut in the %All Users% folder
    – Moab
    Jun 13, 2021 at 23:01
  • 1
    @Subham it is not possible to do what you ask. You have no way of knowing where the code folder is on someone else’s computer. You have to have an installer that puts the files in the user’s chosen location and builds the shortcuts relative to that. You’re making an assumption about someone else’s choices or configuration and it will not be reliable. Jun 14, 2021 at 1:22
  • 1
    @Subham yes. Then it works using the %userprofile% variable as you did. What error are you receiving? Please edit your post and add in more detail. Jun 14, 2021 at 5:01

2 Answers 2


Shortcuts do not support relative paths. It really is as simple as that. Developers commonly use Batch files (.bat) for what you describe.

However, I found an interesting alternative using Windows Explorer as an intermediate:

  1. Under the “Shortcut” tab delete “C:\Windows” in “Start in” field to make it blank. This ensures that the shortcut will start in its current path.
  2. In Target field add this: %windir%\explorer.exe. Following it, add the relative path to your program in double-quotes. For example, %windir%\explorer.exe "\your\folder\app.exe” or %windir%\explorer.exe "..\my\files"


You may still have icon trouble with this method, but this is the best you can do.

  • I tried this method, but now the exe can't find the files to make the game run. I looked at your source and tried the bat method, but similar issue.
    – Subham
    Jun 14, 2021 at 19:00
  • So your program probably relies on its working directory instead of its location. You can fix that.
    – Daniel B
    Jun 14, 2021 at 21:48
  • How do I fix that?
    – Subham
    Jun 14, 2021 at 23:33
  • Would you please tell me what I can do?
    – Subham
    Jun 15, 2021 at 18:38
  • I cannot. I don’t know any details about your game. Maybe cd to the directory inside your code.
    – Daniel B
    Jun 15, 2021 at 20:01

This is a slightly different problem, but the solution may be of use.
I have a large collection of ePub (Book) files stored in a tree structure by genre and author name. [eg. Q:\SFF\B\Bloggs, Fred\Space Wars.epub]. When an author uses a number of pen-names, I put shortcuts in the author folder pointing to the alternate folders with the other names. When I copied the entire Library to a portable hard drive, the shortcuts failed.
The solution was to create an Environment Variable "Z" with value of the original drive path [in this case "Q:\"] on the source PC.
Then right-click on the shortcut and select "Properties".
In the "Target" area, replace the Drive [in this case "Q:\"] with "%Z%" and save. [If the Environment variable does not complete a path to an existing file or folder, save will not work.]
When the portable drive is plugged into another PC, it could be assigned any drive letter. Set [or change] the value for the Environment Variable "Z" to the correct drive letter and then all the modified shortcuts will work.
I chose "Z" but the Environment variable could have any (unused) name. "%Z%" has the same number of characters as "Q:\" and I have not yet written a program to scan my library and modify all the shortcuts to relative - that's the next major project.

The following batch file "Z_Relative.bat" placed on the portable drive can be run to set the Environment Variable.

    @echo off
    REM Batch file to set the Environment Variable "Z" to the current drive.
    REM Place in root directory of USB drive to setup relative shortcuts 
    REM     WITHIN the drive if run from there.

    IF NOT %Z%==%CD% SETX Z %CD%

(This is required because %CD% only works in Command Prompts and won't work in a shortcut.)


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .