user3008146
user3008146

Reputation:

Why does my batch file not continue execution after running Diskpart in WinPE?

I am trying to create a batch file to run in WinPE. I would like to know how to run a large batch file which calls diskpart then exits and continues running the batch file. When I call diskpart it just exits after running the diskpart part. I know how to run a diskpart batch file.

 @echo off
diskpart /s createparts.txt

Here is the sample diskpart batch file I am using to create partitions. I wish to run copyimg.bat at the end of the file to continue the automated processing which is going to copy an image to the newly partitioned drive.

select disk 0 
CREATE PARTITION PRIMARY size=100
format quick fs=ntfs label="OS"
assign letter="c"
active 
CREATE PARTITION PRIMARY 
format quick fs=ntfs 
assign letter=d 
exit
call copyimg.bat

I know I am calling exit before calling copyimg.bat, however I need to exit from diskpart before running other non diskpart related scripts.

Upvotes: 0

Views: 2751

Answers (3)

I had the same problem for another script. After call it instead of continue and execute the following commands, it was stopping. I solved it with cmd /C, as example:

cmd /C my_script_file.bat
another_command
more_stuff_here

Upvotes: 0

Harry Johnston
Harry Johnston

Reputation: 36348

You can't mix batch commands and diskpart commands in the same file. You already have two files, but you're putting the extra batch commands in the wrong place.

The batch file should look like this:

@echo off
diskpart /s createparts.txt
call copyimg.bat

The diskpart file createparts.txt should look like this:

select disk 0 
CREATE PARTITION PRIMARY size=100
format quick fs=ntfs label="OS"
assign letter="c"
active 
CREATE PARTITION PRIMARY 
format quick fs=ntfs 
assign letter=d 
exit

When diskpart reaches the end of its instructions, it will exit and the batch processor will resume from the point where it left off.

Upvotes: 1

RGuggisberg
RGuggisberg

Reputation: 4750

Put all of your lines from "select disk 0" through "exit" in a file like DiskPartCmds.txt and then replace those lines in your bat file with this line.

DiskPart.exe < DiskPartCmds.txt

Upvotes: 0

Related Questions