Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In my case, I have an executable in a different folder to the data, and am linking them using shortcuts with the Start In dir modified, for example:

C:/Test - Data dir
C:/Test/3 - Exe dir

Shortcut: C:/Test/3/test3.exe :: Start In C:/Test

However I require an automated method of generating shortcuts, so I have a batch file which creates a shortcut of the current dir exe on the desktop, but because I don't know how to change the start in dir, they don't work.

share|improve this question

migrated from Oct 30 '12 at 19:48

This question came from our site for professional and enthusiast programmers.

StackOverflow is for programming problems. If you are looking for an existing tool, then you want SuperUser. – Raymond Chen Oct 30 '12 at 4:06
I also vote for moving to Superuser, provided OP does not changes it into a programming question: "How to programmatically create a shortcut?". For a solution in Delphi see How to Create a Windows Shortcut (.LNK) File by Zarko Gajic , Guide. – PA. Oct 30 '12 at 8:32
Does writing a batch file not count? Alright, guess I'll take a look at Delphi then. Though even that link doesn't include setting a shortcut's 'Start In' path. – user1784489 Oct 30 '12 at 15:55

1 Answer 1

I use this batch file. As you can see, I'm not the original author (someone clever called Walter Zackery), I've just tweaked it in a couple of places (where it says changed by gw)

It doesn't answer your title question since it doesn't set the Start In directory. It should do what you describe in the question details though.

Example call:

link c:\Test\3\test3.exe "my shortcut" c:\test\x.txt some_other_parameter another_parameter

This would use test3.exe to open x.txt in the test directory, with some other parameters (the other parameters cannot be quoted ones.)

::Subject:      Re: Shortcut in start menu
::Date:         Mon, 27 Dec 1999 06:34:17 -0500
::From:         "Walter Zackery" <>
::Organization: Prodigy Internet
::Newsgroups:   alt.msdos.batch
::References:   1 , 2 , 3
::I posted this in an NT group 2 weeks ago, but here it is again.

::Parameter number one must be the complete path of the file or folder
::that you're trying to create a shortcut to.
::Parameter number two must be the complete path of the folder that you
::wish to locate the shortcut in.
::Parameter number three is the trickiest. It must be the complete path
::to the Programs folder. The Programs folder is the folder that
::contains your Start Menu shortcuts. It's normal location is
::c:\windows\start menu\programs, or possibly
::c:\windows\profiles\xxx\start menu\programs, where xxx is your user
::name if you're using profiles. It's possible to obtain the location of
::the Programs folder using a batch file, but doing so would more than
::double the size of the batch file, so I refrained.
::Parameter number four must be the name that you wish to give to the
::shortcut. Don't attach the LNK extension to this name, because Windows
::will do it for you when it creates the shortcut.
::Here's an example command line for the batch file.
::link.bat c:\windows\notepad.exe c:\windows\desktop  "A Notepad Shortcut" fred.txt

:: gw 22/5/9 made certain changes:
::      uses reg not regedit, since regedit export format changed
::      can pass parameter 3 for shortcut name
::      can pass parameter 4 ,5, .. 9 for command line parameters after name, these 
::      will NEVER be quoted in the shortcut so make sure to use short paths

::@echo off
::For Windows NT 4.0 users only!!!
::Creates LNK and PIF files from the command line.
::Author: Walter Zackery
if not %1[==[ if exist %1 goto start
@echo You must pass the path of a file or folder to the
@echo batch file as a shortcut target.
@if not %1[==[ echo %1 is not an existing file or folder
(pause & endlocal & goto:eof)

:: gw changed so can pass name as parameter 2
if %3_==_ for /f "tokens=*" %%? in (
'dir/b/a %1? 2^>nul') do (set name=%%~nx?)
if %name%_==_ set name=%3

(set hkey=HKEY_CURRENT_USER\Software\Microsoft\Windows)
(set hkey=%hkey%\CurrentVersion\Explorer\Shell Folders)
(set inf=rundll32 setupapi,InstallHinfSection DefaultInstall)

:: gw - replaced with reg call to get inot NT4 format which findstr understands
::start/w regedit /e %temp%\#57#.tmp "%hkey%"

reg export "%hkey%" %temp%\#57#.tmp /nt4

for /f "tokens=2* delims==" %%? in (
'findstr/b /i """desktop"""= %temp%\#57#.tmp') do (set d=%%?)

for /f "tokens=2* delims==" %%? in (
'findstr/b /i """programs"""= %temp%\#57#.tmp') do (set p=%%?)
(set d=%d:\\=\%) & (set p=%p:\\=\%)
if not %2[==[ if exist %~fs2\nul (set d=%~fs2)
if not %2[==[ if exist %~fs2nul (set d=%~fs2)
set x=if exist %2\nul
if not %2[==[ if not %d%==%2 %x% if "%~p2"=="\" set d=%2
echo %d%|find ":\" >nul||(set d=%d%\)
(set file=""""""%1"""""")

if %4_==_ goto create_file

:: can't even get quotes in with this indirect method
:: if %4==/q (
::     set params=%params% "
::     set first_in_quotes=true
:: ) else if %4==\q (
::     set params=%params%"
:: ) else if first_in_quotes==true (
::     set params=%params%%4
::     set first_in_quotes=
:: ) else set params=%params% %4

set params=%params% %4

goto set_params

for /f "tokens=1 delims=:" %%? in ("%file:"=%") do set drive=%%?
(set progman=setup.ini, progman.groups,,)
echo > %temp%\#k#.inf [version]
echo >>%temp%\#k#.inf signature=$chicago$
echo >>%temp%\#k#.inf [DefaultInstall]
echo >>%temp%\#k#.inf UpdateInis=Addlink
echo >>%temp%\#k#.inf [Addlink]
echo >>%temp%\#k#.inf %progman% ""group200="}new{"""
echo >>%temp%\#k#.inf setup.ini, group200,, """%name%"",%file% %params%
start/w %inf% 132 %temp%\#k#.inf
del %temp%\#k#.inf %temp%\#57#.tmp
move %p%\"}new{\*.*" %d% >nul 2>&1
rd %p%\}new{ 2>nul
move %p%\}new{.lnk %d%\"drive %drive%.lnk" >nul 2>&1
share|improve this answer
I think I understand it a little bit. Many thanks, I'll give it a shot! – user1784489 Oct 30 '12 at 19:36
EDIT For those interested, I am trying to make a game mod launcher with the same name and used files as the original game, but located in an external folder. The idea is that users can drop this bat file into their game directory and have it set up a working shortcut. In other words: check for existence of exe file, create shortcut on desktop with start in path = base game and target path = mod exe – user1784489 Oct 30 '12 at 19:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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