How to change working directory to another drive

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" - ur00361883 7 years ago

Answers (4)

Posted by: anonymous_9363 7 years ago
Red Belt
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.

  • 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:\ - ur00361883 7 years ago
Posted by: anonymous_9363 7 years ago
Red Belt
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.
Posted by: EdT 7 years ago
Red Belt
Any reason why ROOTDRIVE cannot be used to set the working drive letter?  Then all references are automatically adjusted.

  • 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". - ur00361883 7 years ago
    • 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. - EdT 7 years ago
      • It is still showing the c:\ drive - ur00361883 7 years ago
Posted by: Rajendra_447 7 years ago
White Belt
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.

  • 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. - ur00361883 7 years ago
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