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
Easiest Solution:> Enviroment Variables handy little critters.
If the other person is to install/uncompress whatever to wherever on their respective system drive (usualy c:).
For demonstration purposes call our app "test.exe" (could be any executable/file doesn't have to be exe) and it is to be installed/uncompressed to folder MYCOMPANY\MYAPP\
Then just make a shortcut that uses %SystemDrive%\MYCOMPANY\MYAPP\test.exe as target and %SystemDrive%\MYCOMPANY\MYAPP\ as start in.
So now you would like to deploy it. Using an app like "WinRAR".
Easy way is using self-extraction zip file, neatly packaged as an ".exe" I would use one for my shortcut and another for the app. There is ways to make one self-extraction zip file that extracts different files to different directories, but i haven't played with it yet.
Another way is to make a selfextract for the shorcut, embed it inside the selfextract for the app and then apply a run once script,being that you know where the file is going to be. etc.
If you want to enable the installer to use custom installation/uncompress directories, then rather have a look at NSIS a scriptable install system.
Play around it's fun, hope my info helped.
Just a small improvement to leoj3n's solution (to make the console window disappear): instead of putting %windir%\system32\cmd.exe /c start "" "%CD%\bat\bat\run.bat"
to the Target: field of your Windows shortcut, you can also try adding only the following: %windir%\system32\cmd.exe /c "%CD%\bat\bat\run.bat"
AND then also adding start
in front of your commands in run.bat
. That will make the console window disappear, but everything else remains the same.
You could have the batch file change the current working directory (CD).
I like leoj3n's solution. It can also be used to set a relative "start in" directory, which is what I needed by using start's /D parameter. Without /c or /k in as an argument to cmd, the subsequent start command doesn't run. /c will close the shell immediately after running the command and /k will keep it open (even after the command is done). So if whatever you're running spits to standard out and you need to see it, use /k.
Unfortunately, according to the lnk file specification, the icon is not saved in the shortcut, but rather "encoded using environment variables, which makes it possible to find the icon across machines where the locations vary but are expressed using environment variables." So it's likely that if paths are changing and you're trying to take the icon from the executable you're pointing to, it won't transfer correctly.
Right click on your /bat/ folder and click Create Shortcut.
bat - Shortcut
in the current directory.Shortcut to bat
.Right click on the shortcut you just created and click Properties.
Change Target (under the Shortcut tab on Windows 7) to the following:
%windir%\system32\cmd.exe /c start "" "%CD%\bat\bat\run.bat"
Make sure Start in is blank. That causes it to start in the current directory.
That's probably acceptable in the case of shortcutting to a .bat but if you want to change the icon, open the shortcut's properties again and click Change Icon... (again, under the Shortcut tab on Windows 7). At this point you can Browse... for an icon or bring up a list of default system icons by entering
%SystemRoot%\system32\SHELL32.dll
to the left of the Browse...
button and hitting Enter. This works on Windows 7 and Windows XP but the icons are different due to style updates (but are recognizably similar). Depending on the version of Windows the shortcut resides, the icon will will sometimes change accordingly.
More Info:
See Using the "start" command with parameters passed to the started program to better understand the empty double-quotes at the beginning of the first Target command.
After reading several answers, I decided to do it with a simple solution: Instead of a shortcut, I made a .bat with only one line to call the main .bat and it works like I wanted.