Search code examples
batch-filepartitiondiskpart

Batch file with disk part


I've been trying to create a batch file that calls out diskpart commands and then exits back to the batch file. The diskpart commands increase the size of the recovery partition.

Here is the current batch file I have:

@echo off
reagentc /disable
diskpart /s diskpartincreasepartition.txt
reagentc /enable
exit /b

And here's what I have in the diskpartincreasepartition.txt file:

diskpart
list disk
sel disk 0
list part
sel part 5
shrink desired=1000 minimum=1000
sel part 4
delete partition override
create partition primary id=de94bba4-06d1-4d40-a16a-bfd50179d6ac
gpt attributes =0x8000000000000001
format quick fs=ntfs label="Windows RE tools"
exit

Right now, it just calls diskpart and doesn't do anything else. I have both the .bat and .txt files saved to my USB drive with nothing else on it. I am running the .bat file that calls out the .txt file. What am I doing wrong here?


Solution

  • Your script looks for the diskpartincreasepartition.txt in the current working folder - which may be the same folder where the batch script is located, or a completely different one (usually). It doesn't find the file there, so diskpart has nothing to do. Give it the full path:

    diskpart /s "%~dp0diskpartincreasepartition.txt"