Page 1 of 1

set /p Select=Enter y: Not working

Posted: 09 Feb 2021 18:03
by Docfxit
I created this bat script to fix a computer that won't boot. It needs the ESP partition fixed so I can make it bootable.
I'm having trouble with one SET statement that isn't doing what I want it to do. I can't figure out why.
Towards the end of the code you will see:
:: *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
:: When I enter a lower case y it goes to :eof. I want it to continue with the bat file.
:: *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

That's where the problem is.

Please help me fix it.

Thank you,

Docfxit

Code: Select all

@echo on
:: *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
::  Warning!!!
::    Do not run this on your computer.  It is customized for my computer.
::        Your computer will probably be different.
::  **************   This could cause harm to your computer.  ***********
:: *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

:: 1. Boot from your bootable medium
:: Make sure that you are booting in UEFI mode
:: 2. At the first screen (where it asks you to choose language and keyboard), 
::    press Shift + F10. This will give you a command prompt.
echo > USBMakeBootable.scr list disk
echo >>USBMakeBootable.scr exit
diskpart /s USBMakeBootable.scr
set /p Disk=Please enter the disk number: 
if "%Disk%"=="" goto :eof

echo >USBMakeBootable.scr Select disk %Disk%
echo >> USBMakeBootable.scr list partition
echo >>USBMakeBootable.scr exit
diskpart /s USBMakeBootable.scr
set /p Partition=Please enter the system partition number: 
::  make sure that there is a partition of type system (the efi partition).
if "%Partition%"=="" goto :eof

echo >USBMakeBootable.scr Select disk %Disk%
echo >>USBMakeBootable.scr Select partition %Partition%
echo >>USBMakeBootable.scr assign letter=G
echo >>USBMakeBootable.scr list vol
echo >>USBMakeBootable.scr exit
diskpart /s USBMakeBootable.scr
@Echo Off
Echo "You should see a volume with drive letter (Ltr) as G"
Echo "file system (Fs) as FAT32"
Echo .
set /p Select=Enter y: 
if "%Select%"=="y" (
    ECHO Yes
) ELSE (
echo >USBMakeBootable.scr Select disk %Disk%
echo >>USBMakeBootable.scr Select partition %Partition%
echo >>USBMakeBootable.scr list vol
echo >>USBMakeBootable.scr exit
diskpart /s USBMakeBootable.scr
Echo "You should see a volume with drive letter (Ltr) as G"
Echo "file system (Fs) as FAT32"
Echo .
set /p Select=Enter y: 
:: *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
::  When I enter a lower case y it goes to :eof.  I want it to continue with the bat file.
:: *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
if /I "%Select%"=="y" (
    ECHO Yes
) ELSE (
    goto :eof
)
)
echo >USBMakeBootable.scr Select disk %Disk%
echo >>USBMakeBootable.scr Select partition %Partition%
echo >>USBMakeBootable.scr  detail partition
echo >>USBMakeBootable.scr exit
diskpart /s USBMakeBootable.scr

Echo "Is drive letter (Ltr) G (Info) Hidden?"
Echo .

set /p Select=Enter y: 
if "%Select%"=="y" (
    
echo >USBMakeBootable.scr Select disk %Disk%
echo >>USBMakeBootable.scr Select partition %Partition%
echo >>USBMakeBootable.scr  set id = 07 override
echo >>USBMakeBootable.scr  detail partition
echo >>USBMakeBootable.scr exit
diskpart /s USBMakeBootable.scr
) 

GoTo :Skip
echo >>USBMakeBootable.scr clean
echo >>USBMakeBootable.scr create part pri
echo >>USBMakeBootable.scr select part 1
echo >>USBMakeBootable.scr format fs=ntfs quick
echo >>USBMakeBootable.scr active
echo >>USBMakeBootable.scr exit
echo diskpart /s USBMakeBootable.scr
:Skip
:eof
del USBMakeBootable.scr
cmd /k

Re: set /p Select=Enter y: Not working

Posted: 09 Feb 2021 19:54
by T3RRY
You've made a typo, one closing parentheses too many.

I dont understand why your not just using choice.

Code: Select all

For /F "delims=" %%G in ('Choice /N /C:YN')Do If %%G==N goto :Eof

Re: set /p Select=Enter y: Not working

Posted: 09 Feb 2021 20:01
by Docfxit
Thank you for the reply...

Do you see the open parentheses at:

Code: Select all

Echo "file system (Fs) as FAT32"
Echo .
set /p Select=Enter y: 
if "%Select%"=="y" (
    ECHO Yes
) ELSE (
Is Choice available while I'm booted in windows repair? Windows 8

Thanks,

Docfxit

Re: set /p Select=Enter y: Not working

Posted: 09 Feb 2021 20:51
by ShadowThief
The improper indentation threw me off for a second, but I see now that the %select% variable isn't returning a value because you're both setting and using it inside of the same set of parentheses. If you want to do that, you need to add the line setlocal enabledelayedexpansion to the top of the script and use !select! instead of %select%.

Also, Windows 8 has choice, so you'll be fine using that if you want.

Re: set /p Select=Enter y: Not working

Posted: 09 Feb 2021 21:44
by Docfxit
Thank you for the reply...

I'm getting a new error:
At this line:
echo >USBMakeBootable.scr list disk

It isn't writing out the file.

Code: Select all

@echo on
:: *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
::  Warning!!!
::    Do not run this on your computer.  It is customized for my computer.
::        Your computer will probably be different.
::  **************   This could cause harm to your computer.  ***********
:: *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

:: 1. Boot from your bootable medium
:: Make sure that you are booting in UEFI mode
:: 2. At the first screen (where it asks you to choose language and keyboard), 
::    press Shift + F10. This will give you a command prompt.
setlocal enabledelayedexpansion
echo >USBMakeBootable.scr list disk
echo >>USBMakeBootable.scr exit
	rem *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
	rem  I'm getting an error saying "The system cannot find the file specified."
	rem *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

diskpart /s USBMakeBootable.scr
set /p Disk=Please enter the disk number: 
if "%Disk%"=="" goto :eof

echo >USBMakeBootable.scr Select disk %Disk%
echo >> USBMakeBootable.scr list partition
echo >>USBMakeBootable.scr exit
diskpart /s USBMakeBootable.scr
set /p Partition=Please enter the system partition number: 
::  make sure that there is a partition of type system (the efi partition).
if "%Partition%"=="" goto :eof

echo >USBMakeBootable.scr Select disk %Disk%
echo >>USBMakeBootable.scr Select partition %Partition%
echo >>USBMakeBootable.scr assign letter=G
echo >>USBMakeBootable.scr list vol
echo >>USBMakeBootable.scr exit
diskpart /s USBMakeBootable.scr
@Echo Off
Echo "You should see a volume with drive letter (Ltr) as G"
Echo "file system (Fs) as FAT32"
Echo .
set /p Select=Enter y: 
if "%Select%"=="y" (
    ECHO Yes
) ELSE (
	echo >USBMakeBootable.scr Select disk %Disk%
	echo >>USBMakeBootable.scr Select partition %Partition%
	echo >>USBMakeBootable.scr list vol
	echo >>USBMakeBootable.scr exit
	diskpart /s USBMakeBootable.scr
	Echo "You should see a volume with drive letter (Ltr) as G"
	Echo "file system (Fs) as FAT32"
	Echo .
	set /p Select=Enter y: 
	if /I "!Select!"=="y" (
		ECHO Yes
		) ELSE (
			goto :eof
		)
	rem *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
	rem  I tried the next line with Choice instead of the If /I Select.  It didn't recognize Choice in Windows Repair
	rem *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
rem For /F "delims=" %%G in ('Choice /N /C:YN')Do If %%G==N goto :Eof
)
echo >USBMakeBootable.scr Select disk %Disk%
echo >>USBMakeBootable.scr Select partition %Partition%
echo >>USBMakeBootable.scr  detail partition
echo >>USBMakeBootable.scr exit
diskpart /s USBMakeBootable.scr

Echo "Is drive letter (Ltr) G (Info) Hidden?"
Echo .

set /p Select=Enter y: 
if "%Select%"=="y" (
    
echo >USBMakeBootable.scr Select disk %Disk%
echo >>USBMakeBootable.scr Select partition %Partition%
echo >>USBMakeBootable.scr  delete partition override
echo >>USBMakeBootable.scr  detail partition
echo >>USBMakeBootable.scr exit
diskpart /s USBMakeBootable.scr
) 

GoTo :Skip
rem After the boot records are written hide the partition with this:
echo >USBMakeBootable.scr Select disk %Disk%
echo >>USBMakeBootable.scr Select partition %Partition%
echo >>USBMakeBootable.scr  set id=c12a7328-f81f-11d2-ba4b-00a0c93ec93b
echo >>USBMakeBootable.scr  detail partition
echo >>USBMakeBootable.scr exit
diskpart /s USBMakeBootable.scr

echo >>USBMakeBootable.scr clean
echo >>USBMakeBootable.scr create part pri
echo >>USBMakeBootable.scr select part 1
echo >>USBMakeBootable.scr format fs=ntfs quick
echo >>USBMakeBootable.scr active
echo >>USBMakeBootable.scr exit
echo diskpart /s USBMakeBootable.scr
:Skip
:eof
del USBMakeBootable.scr
cmd /k

Re: set /p Select=Enter y: Not working

Posted: 10 Feb 2021 12:04
by ShadowThief
I was going to tell you that that line would redirect the output of echo to USBMakeBootable.scr and ignore the list disk bit (because normally you'd use >USBMakeBootable.scr echo list disk), but that totally works. Make sure you're in the right directory.

Re: set /p Select=Enter y: Not working

Posted: 11 Feb 2021 10:09
by Docfxit
I re-typed the line and it worked again.

Thank you,

Docfxit