Batch to reassign drive letter based on volume name

2

I have a "WINPE" volume and I am trying to get a batch script that will assign it drive letter "Z:"

Someone gave me the script below but it does not work

    for /f %%D in ('wmic volume get DriveLetter^, Label ^| find "WINPE"') do set myDrive=%%D
    @echo off
    echo ===============================================================================
    echo.                          Mobile Repairs Install
    echo ===============================================================================
    echo.                   1 - Install Windows 7 Home Premium
    echo.                   2 - Install Windows 7 Prefessional
    echo.                   3 - Install Windows 8.1
    echo ===============================================================================
    echo.                            Press Zero '0' to Quit
    echo ===============================================================================

    echo off
    :begin
    echo Select a task:
    echo =============
    set /p op=Type option:
    if "%op%"=="1" goto op1
    if "%op%"=="2" goto op2
    if "%op%"=="3" goto op3
    if "%op%"=="0" goto op0


    echo Please Pick an option:
    goto begin


    :op1
    %myDrive%
    diskpart /s diskpartrans.txt
    imagex /apply install7Pre.wim 1 c:
    c:\windows\system32\bcdboot c:\windows
    c:\Windows\system32\shutdown /r /t 0
    goto end

    :op2
    %myDrive%
    diskpart /s diskpartrans.txt
    imagex /apply install7Pro.wim 1 c:
    c:\windows\system32\bcdboot c:\windows
    c:\Windows\system32\shutdown /r /t 0
    goto end


    :op3
    %myDrive%
    diskpart /s diskpartrans.txt
    imagex /apply install8.wim 1 c:
    c:\windows\system32\bcdboot c:\windows
    c:\Windows\system32\shutdown /r /t 0
    goto end

    :op0
    exit

    :end  

Emery Williams

Posted 2015-07-24T20:11:21.700

Reputation: 31

Debugging your batch files – DavidPostill – 2015-07-24T20:19:46.797

That didn't help me. I am sorry – Emery Williams – 2015-07-25T14:43:37.837

"Does not work" is not very useful - are there any messages? Are you running the script as an admistrator? What is your operating system? – DavidPostill – 2015-07-25T16:27:27.863

I am trying to run a script from within a bootable WINPE drive I mounted the boot.wim and made a bat with for /f %%D in ('wmic volume get DriveLetter^, Label ^| find "WINPE"') do set myDrive=%%D referring it to use %myDrive%. I have used the debugging and it found no errors as it works on cmd just not under WINPE cmd – Emery Williams – 2015-07-25T17:50:16.867

I edited the original post with my exact script I just made – Emery Williams – 2015-07-25T17:55:51.017

So you have a different script. You still just say "Does not work". What is it supposed to do that it doesn't. I've no idea what "Does not work" means. You have to tell us if you want help. – DavidPostill – 2015-07-25T17:58:11.203

My apologies I am new batch files and the board. I am trying to get the script to run under WINPE – Emery Williams – 2015-07-25T17:59:31.083

I know that. What doesn't work?. Which bit of the script does the Wrong thing? – DavidPostill – 2015-07-25T18:01:01.037

Whenever I run the script in WINPE it doesn't change the drive from X: to %myDrive% but if it run the script under Windows 7 CMD it does – Emery Williams – 2015-07-25T18:01:30.533

I am not good at explaining via typing anyway to help by phone? – Emery Williams – 2015-07-25T18:02:03.980

Whenever I run the script in WINPE it doesn't change the dir not drive from X: to %myDrive% but if it run the script under Windows 7 CMD it does – Emery Williams – 2015-07-25T18:02:46.430

What drive are you on when you run the script? – DavidPostill – 2015-07-25T18:03:26.877

Try using cd /d %myDrive% instead of %myDrive% – DavidPostill – 2015-07-25T18:05:04.347

Add echo %myDrive% as the second line of the script. What does it output? – DavidPostill – 2015-07-25T18:15:01.513

I just tried it with your suggestion and I got The Filename, directory name, or volume label syntax is incorrect. – Emery Williams – 2015-07-25T18:19:58.997

Please run wmic volume get DriveLetter, Label from a command line and [edit] the question to include the output from this as well as the output from echo %myDrive% in the batch file. – DavidPostill – 2015-07-25T18:32:56.703

When I put echo %myDrive% as the second line it just does

ECHO is on – Emery Williams – 2015-07-25T18:38:11.147

So the for /f isnt working. Please run wmic volume get DriveLetter, Label from a command line and edit the question to include the output from this – DavidPostill – 2015-07-25T18:39:13.750

Answers

1

Okay I have figured it out. I mounted the WinPe boot.wim copied WMIC from my windows 8.1 to the system32 dir and a bat with this code

    @echo off
    for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (vol %%a: 2>nul | find "WINPE" >nul
    if not errorlevel 1 set myDrive=%%a:)
    if "%myDrive%"=="" (echo Cannot find volume
    ) else (
    echo CD /D %myDrive%)>> output.bat
    )
    echo installs>> output.bat

    output.bat 

This sets an output batch with the drive letter that I need. Then it runs that batch file which looks like this

    CD /D h:
    installs
    CD /D g:
    installs

That runs my install batch which is this

    echo ===============================================================================
    echo.                          Mobile Repairs Install
    echo ===============================================================================
    echo.                   1 - Install Windows 7 Home Premium
    echo.                   2 - Install Windows 7 Professional
    echo.                   3 - Install Windows 8.1 OEM
    echo.                   4 - Install Windows 8.1 Professional OEM
    echo.                   5 - Install Windows 8.1 OEM UEFI
    echo.                   6 - Install Windows 8.1 Professional OEM UEFI
    echo ===============================================================================
    echo.                            Press Zero '0' to Quit
    echo ===============================================================================

    echo off
    :begin
    echo Select a task:
    echo =============
    set /p op=Type option:
    if "%op%"=="1" goto op1
    if "%op%"=="2" goto op2
    if "%op%"=="3" goto op3
    if "%op%"=="4" goto op4
    if "%op%"=="5" goto op5
    if "%op%"=="6" goto op6
    if "%op%"=="0" goto op0

    echo Please Pick an option:
    goto begin


    :op1
    win7pre.bat
    goto end


    :op2
    win7pro.bat
    goto end


    :op3
    win8bios.bat
    goto end


    :op4
    win8probios.bat
    goto end


    :op5
    8oemuefi.bat
    goto end


    :op6
    8prouefi.bat
    goto end

    :op0
    exit

Emery Williams

Posted 2015-07-24T20:11:21.700

Reputation: 31

Seems like a lot but it works and I can now install windows in 2 minutes from a Wim file – Emery Williams – 2015-07-28T15:22:36.907