Scripting Question

How to change working directory to another drive

12/23/2016 1369 views
I am copying a batch file in c:\ or d:\ based on user preference and will set the shortcut properties as below.

I am setting the "Start In" to the location where batch file is there.
But when I launch the shortcut the current working directory is still c:\windows\system32.

Any suggestion please how to set the working directory to Start In folder.
1 Comment   [ + ] Show comment


  • As a temporary fix, I have added below line in the batch file itself to pick the working directory instead of depending on StartIn option in shortcut properties.

    cd /d "%~dp0"

Community Chosen Answer

Batch files are executed by the command processor which lives in that folder.

If you need the batch file's "content" to be drive/folder-specific, use "CD /D [path to change to]" in the file.
Answered 12/23/2016 by: VBScab
Red Belt

  • No I didn't mean that.

    What I want is to set the working directory to the folder where batch file exists.

    If the user is installing the msi to a different drive like some E:\ , the shortcut is getting set as it is with the StartIn option.

    But the batch file execution is still taking C:\windows\system32.

    This is working file if choose a different folder in C:\ drive itself.

    The problem occurs when I change the drive to some other logical drive instead of the primary partition C:\

All Answers

That's a different problem, then.

You need to set the 'Start In' folder using the value of the INSTALLDIR property. Use the Shortcut table.
Answered 12/23/2016 by: VBScab
Red Belt

Any reason why ROOTDRIVE cannot be used to set the working drive letter?  Then all references are automatically adjusted.
Answered 12/24/2016 by: EdT
Red Belt

  • Actually it is setting fine in the shortcut properties..But the batch file is not working..So I kept pause for troubleshooting and when I checked that commadn prompt, it is showing the workign directory to system32 folder instead of the one in "Strat In".
    • Instead of calling the batch file directly, which invokes CMD.EXE from the system32 folder, try calling c:\windows\system32\cmd.exe /c <path to batch file> and see if the start in folder is then correct. If there is still a problem, the solution is to add code to your batch file to identify the drive letter you are running from and then change drive letter and directory to the location that the start in folder should be pointing to.
      • It is still showing the c:\ drive
Yes. We can use ROOTDRIVE and set the value as C:\ or D:\ as per your requirements. Then it will redirect the shortcut directory to the respective drive. It works perfect.
Answered 12/25/2016 by: Rajendra_447
White Belt

  • THanks Rajendra for your inputs..But the issue is not with msi installation.The shortut is showing the startin settings correctly.

    But the batch file is not picking the startin folder at runtime.
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ