Britec Tech Support Forum

Full Version: HOW TO AUTOMATE DISKPART USING A BATCH FILE
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello Brian and Administrators

I am trying to run DISKPART from a batch file to save keying in all the commands every time I want to make a USB stick bootable!

Although there seem to be numerous solutions on the Internet I have yet to find one which works.
I am running the latest version of Windows 10 PRO.

I would like to open a command prompt, with administrator rights, to enter the following sequence of commands (without numbers 1 to 9):-

1.  diskpart
2.  list disk
3.  select disk
4.  clean
5.  create partition primary
6.  select partition 1
7.  active
8.  format fs=fat32 quick
9.  assign
Type EXIT and ENTER to finish

I also want to be able to enter "LIST DISK" and "SELECT DISK" with an input choice for the disk number.

I know you guys make "great videos" but as long as you can give me clear instructions, details could come just as coding!
Please specify any file(s) I need to produce.

Thank you for any assistance you can give!

Kind Regards
Mike-m5
Mike-m5 you are double posting the same questions

you already have an open thread https://briteccomputers.co.uk/forum/showthread.php?tid=4131
Credit goes to Even Greene Add the snippet code to the top of your batch file and it will run as administrator

Code:
@echo off


:: Get ADMIN Privs
:-------------------------------------
mkdir "%windir%\BatchGotAdmin"
if '%errorlevel%' == '0' (
  rmdir "%windir%\BatchGotAdmin" & goto gotAdmin 
) else ( goto UACPrompt )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    echo UAC.ShellExecute %0, "", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
    pushd "%CD%"      
    CD /D "%~dp0"
:-------------------------------------
:: End Get ADMIN Privs

<YOUR BATCH SCRIPT HERE>