0

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?

8
  • 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

1 Answer 1

0

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"

Source

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

5
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.