Making a Windows shortcut start relative to where the folder is?

后端 未结 15 2429
自闭症患者
自闭症患者 2020-11-30 20:36

I have a game that uses this file structure:

GAME FOLDER
->data
->data->run.bat

I want to put a shortcut to run.bat i

相关标签:
15条回答
  • 2020-11-30 20:51

    I'm not sure if I'm right, or I'm missing something, but as for now (2016-07-11, running Win7 Enterprise SP1) a LNK file adapts itself on moving or even changing the drive letter after it is run at a new place! I created a new shortcut on my USB drive and tried moving the shortcut and its target in a way that the relative position stayed unchanged, then I changed the drive letter. The shortcut worked in both cases and the target field was adapted after I double-clicked it.

    It looks like Microsoft has addressed this issue in one of the past updates.

    Please somebody confirm this.

    0 讨论(0)
  • 2020-11-30 20:54

    If you can set a system variable (something like %MyGameFolder%), then you can use that in your paths and shortcuts, and Windows will fill in rest of the path for you (that is, %MyGameFolder%\data\MyGame.exe).

    Here is a small primer. You can either set this value via a batch file, or you can probably set it programmatically if you share how you're planning to create your shortcut.

    0 讨论(0)
  • 2020-11-30 20:56

    I tried %~dp0 in the Start in field and it is working fine in Windows 10 x64

    0 讨论(0)
  • 2020-11-30 20:57

    You can make a relative shortcut manually by changing the file path. First in the usual context-menu you create a new shortcut of Windows for your file and in the properties -> location of your file:

    %windir%\explorer.exe "..\data\run.bat"

    0 讨论(0)
  • 2020-11-30 20:57

    The link with a relative path can be created using the mklink command on windows command line.

    mklink /d \MyDocs \Users\User1\Documents
    

    This might be the best way to create link because apparently, the behaviour of shortcut can be different perhaps based on the way they are created (UI vs mklink command). I observed some strange behavior with how the shortcuts behave when I change the root folder.

    • There is a weird behaviour on Windows 7 that I tested. Sometimes the the link still just works when the root folder of target is changed (the shortcut properties automatically update to reflect the changed path!). The "start in" field updates automatically as well if it was there.
    • I also noticed that one link doesn't work the first time I change the root path (properties shows old) but it works after the 2nd and everytime after that. The link properties get updated as result of the first run!
    • I also noticed at least for two link, it doesn't update the path and no longer works.
    • From link properties, there is no difference in format of any fields yet the behaviour is different.
    0 讨论(0)
  • 2020-11-30 20:59

    Try using Relative (a Windows command-line application).

    Basically, a shortcut could have a relative link, but Windows gives no way to actually make one.

    0 讨论(0)
提交回复
热议问题