3

I have what I believe to be a unique issue. I don't do a lot of work with batch files, but I think that would be my best option. Here is the situation. I have special software that looks for a perticular cd tray on my system then assigns that letter in the software. The drive I have isn't working, but it does authorize the software to assign that drive as a cd tray. Once the sofware is up and running I can manage my drive letters, swap the working one for the one it sees and then all works out fine. I need to start by making sure I have a set drive letter on both of my drives which I can do at launch using a startup batch file:

Drive 1 : Y
Drive 2 : X

Then after a set amount of time for the software to boot and load the drive, swap the letters.

Drive 1 : X
Drive 2 : Y

To do this I was looking into using a diskpart script, but can't seem to get it to work through a batch file.

volume 0 remove drive letter
volume 1 remove drive letter // this way they are both blank so I don't have conflicting drive letters when I change one without the other
volume 0 set drive letter="Y"
volume 1 set drive letter="X"
wait 5 minutes // software will see volume 1 as X drive
volume 0 remove drive letter
volume 1 remove drive letter
volume 0 set drive letter="X"
volume 1 set drive letter="Y"
// now the software will see X drive as volume 0 making it all work OK.

Might sound weird, but it works when I do it all manually. I need to automate the process for people who start the machine, but don't know how or have time to set it up manually.

thanks for the help.

1
  • "The drive I have isn't working" - why not simply fix the drive? Or remove it altogether?
    – TheCleaner
    Commented Jan 20, 2015 at 14:13

2 Answers 2

3

You can't script with diskpart using batch/cmd commands. Or PowerShell, for that matter. And it doesn't accept arguments like you'd expect it to when you call diskpart.exe. Very irritating, but if you want to programmatically control diskpart, you have to use "diskpart scripts", which are basically just line-break delimited diskpart commands in a text file.

You should be able to call your diskpart script from a batch file with the syntax: diskpart /s scriptname.txt.

3
  • I did try a bat file with diskpart /s scr.txt then had scr.txt with select disk 0 remove select disk 1 remove select disk 0 assign letter="F" select disk 1 assign letter="Y" in it, but I couldn't even drop the drive letter
    – Steve Khalaf
    Commented Jan 19, 2015 at 22:03
  • What do you mean by but I couldn't even drop the drive letter? Commented Jan 19, 2015 at 22:29
  • when doing it in cmd I just type remove, that doesn't work when using script. I have changed it to select the drive number, then used (remove letter="E") and it worked. --- thanks for the help
    – Steve Khalaf
    Commented Jan 19, 2015 at 23:46
-1

You can script using diskpart. ex.

select vdisk file="%driveletter%:\my.vhd"
attach vdisk

This has to be called from the bat file extension

DiskPart /s c:\windows\temp\diskpartscript.txt

if you need to modify the dispartscript.txt during the process use > to carat the response to a text file then call it from your bat

1
  • diskpart  /s scriptfile  was already given in an answer.  What, exactly, are you adding to that?  What does the "vdisk" part of your answer mean?  What does the last sentence of your answer ("... carat the response ...") mean?  Can you back this up with any references? Commented Jun 22, 2015 at 21:45

You must log in to answer this question.