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.)
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
%userprofile%
variable as you did. What error are you receiving? Please edit your post and add in more detail.