Jump to content











Photo
- - - - -

Please help me to go ahead ?

cmd winpe boot.wim usb booting multibooting

  • Please log in to reply
147 replies to this topic

#126 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 13 August 2017 - 12:12 PM

I don't understand what you want to get now.

The partition marked with "*" will be the selected one.

You want all internal partitions, don't you?

What is the output of the:
 

FOR /L %%A IN (1,1,9) DO (
FOR /F "delims=*" %%B IN ('
^(
ECHO SEL DISK 0^&ECHO SEL PAR %%A^&ECHO DET PAR
^)^|DISKPART^|FIND "*" 
') DO CALL :parse_volumes %%B
)
SET Internal
GOTO :EOF
:parse_volumes
SET Line=%*
IF NOT "%Line:~13,1%"==" " SET INTERNAL=!INTERNAL! %Line:~13,1%
GOTO :EOF

On your test machine?

The "Find "*" pipe should limit it to the single partition that is selected :unsure:

 

And what would be the point of removing the subroutine? :dubbio:

 

Anyway:

 

DO SET Line=%%B&&SET INTERNAL=!INTERNAL! !Line:~13,1!

 

:duff:
Wonko



#127 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 13 August 2017 - 01:47 PM

You want all internal partitions, don't you?

Yes

 

What is the output of the:

FOR /L %%A IN (1,1,9) DO (
FOR /F "delims=*" %%B IN ('
^(
ECHO SEL DISK 0^&ECHO SEL PAR %%A^&ECHO DET PAR
^)^|DISKPART^|FIND "*" 
') DO CALL :parse_volumes %%B
)

SET Internal
GOTO :EOF
:parse_volumes
SET Line=%*
IF NOT "%Line:~13,1%"==" " SET INTERNAL=!INTERNAL! %Line:~13,1%
GOTO :EOF
INTERNAL= Z C H F G

The "Find "*" pipe should limit it to the single partition that is selected :unsure:

And what would be the point of removing the subroutine? :dubbio:

I also don't know exactly what I have done. But it gives exactly the same output which I need. It gives me Drive Letters of all partition of Disk 0.

 

Am I using wrong method /approach ? Any better way to get Drive Letter of all partitions of Disk 0 ?



#128 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 13 August 2017 - 02:35 PM

No, that's fine :) , now I see, the loop does run with a selected partition every time, ad thus the "FIND "*" gets just that line, good..

 

The only thing that you can "better" is to avoid the "blind" 1 to 9 loop, it has two kind of issues, it will go on more loops than needed in most cases (when there are less than 9 partitions)  and on not enough in case of more.

Haven't checked, what is the output or list par when there is an Extended partiton (and volumes in it)? :unsure:

 

Removing the external call the drive letter positions is one character off:



@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
SET Internal=
FOR /F "tokens=2 delims= " %%A IN ('^( echo SEL DISK 0^&echo LIST PAR^)^|diskpart^|FIND "Parti"^|FIND /V "."') DO (
FOR /F "delims=*" %%B IN ('^( echo SEL DISK 0^&echo SEL PAR %%A^&echo DET PAR^)^|diskpart^|FIND "*"') DO (
SET Line=%%B
IF NOT "!Line:~14,1!"==" " SET INTERNAL=!INTERNAL! !Line:~14,1!
)
)

SET INTERNAL
GOTO :EOF

:duff:

Wonko


  • devdevadev likes this

#129 cdob

cdob

    Gold Member

  • Expert
  • 1469 posts

Posted 16 August 2017 - 08:04 PM

So there should be no problem if both BIOS and EFI files are within same Boot Partition ?

Yes, there should be no problem if both BIOS and EFI files are within the same Boot Partition.
However there are strange firmware and end users out there. I've the feeling, there are less support request, if you add either or one.

What about a royalty OEM preinstalled Windows?
Do you support this machines?

Example:
There is a NTFS HP_RECOVERY parttion at a UEFI mode HP Z440.
Partition type ebd0a0a2-b9e5-4433-87c0-68b6b72699c7.
There are files \boot\bcd and \efi\microsoft\boot\bcd

And there is a EFI system partition c12a7328-f81f-11d2-ba4b-00a0c93ec93b
There is a file \EFI\Microsoft\Boot\BCD, no \boot\bcd

c12a7328-f81f-11d2-ba4b-00a0c93ec93b is a part of UEFI scepcs. https://en.wikipedia...Partition_Table
Does all manufacturer respect this? Any strange firmwares out there?
What about a missing c12a7328-f81f-11d2-ba4b-00a0c93ec93b partition, but \efi\ at another partition?
As a common configuration, do we use c12a7328-f81f-11d2-ba4b-00a0c93ec93b only?

How does HP recovery works?
Does HP boot \efi\boot\bootx64.efi from the recovery NTFS partition?
Sorry, production machine, no testing.

#130 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 17 August 2017 - 02:17 AM

There is a NTFS HP_RECOVERY parttion at a UEFI mode HP Z440.
Partition type ebd0a0a2-b9e5-4433-87c0-68b6b72699c7.
There are files \boot\bcd and \efi\microsoft\boot\bcd

And there is a EFI system partition c12a7328-f81f-11d2-ba4b-00a0c93ec93b
There is a file \EFI\Microsoft\Boot\BCD, no \boot\bcd

Does NTFS HP_RECOVERY partition at UEFI mode HP H440 Partition type ebd0a0a2-b9e5-4433-87c0-68b6b72699c have a Drive Letter assigned in UEFI WinPE ? If it does not have any Drive Letter in UEFI WinPE, then there should be no issue ? But if it already have a Drive Letter assigned then It is really an issue to consider ??

 

Yes, there should be no problem if both BIOS and EFI files are within the same Boot Partition.

If so then how we can accept this exception in your Boot_Found approach ? 

 

What about a missing c12a7328-f81f-11d2-ba4b-00a0c93ec93b partition, but \efi\ at another partition?

I will manually run WinNTSetup to deal with these machines. As a common configuration, I will look for c12a7328-f81f-11d2-ba4b-00a0c93ec93b only.



#131 Guest_AnonVendetta_*

Guest_AnonVendetta_*
  • Guests

Posted 17 August 2017 - 07:26 AM

https://www.youtube....h?v=0U2zJOryHKQ

 

Or in this case, the thread that never ends. It's hard to believe it's already 6 pages long, especially since the OP titled it "Please help me to go ahead ?". Gee, how descriptive that is, eh? Are you asking a question (the "?" would seem to imply as much)? With a name like that, how are we supposed to know exactly what help is needed with? If OP can't be bothered to write an accurate description of his issue in the title, then I can't be bothered to be of any help (except to post this). And with a name like "devdevadev", you certainly will never be a (software) developer.



#132 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 17 August 2017 - 11:36 AM

If OP can't be bothered to write an accurate description of his issue in the title, then I can't be bothered to be of any help (except to post this). 

 

Very good, and duly noted, thanks for letting us know.

 

:duff:

Wonko



#133 cdob

cdob

    Gold Member

  • Expert
  • 1469 posts

Posted 17 August 2017 - 09:55 PM

But if it already have a Drive Letter assigned then It is really an issue to consider ??

Yes, PE assigns a drive letter. In addition, HP is one example, expect other manufacturer with similar recovery files.

I made new assumptions:
-ID c12a7328-f81f-11d2-ba4b-00a0c93ec93b at a GPT disk is the boot partition. \EFI\Microsoft\boot\BCD is not required.
-most likely the \boot\bcd partition is created first. PE assigns a low letter. A recovery partition is created later, PE assigns a higher letter. Assumption: the first \boot\bcd matching is the boot partiton.


The idea is
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
SET Disk=
SET OSPART=
SET BootPartBIOS=
SET BootPartEFI=
SET CountOSPART=0

REM Detect a GPT disk 0
for /f "skip=9 tokens=2,*" %%a in ('echo list disk ^| diskpart.exe')  do ( 
  set string=%%b
  rem compare last char from string
  if %%a==0 if "!string:~-1!"=="*" (set Disk=GPT& echo Disk !Disk!)
)

REM Search EFI System Partition at a GPT disk 0
if "%Disk%"=="GPT" FOR /L %%a IN (1,1,9) DO (echo sel disk 0
echo sel par %%a
echo det par ) | diskpart.exe | find.exe /I "c12a7328-f81f-11d2-ba4b-00a0c93ec93b" && (
 echo disk 0 partition %%a
 (echo sel disk 0
  echo sel par %%a
  echo remove
  echo assign letter=Z
 ) | diskpart.exe
 set BootPartEFI=Z:& echo BootPartEFI Z:
 if not exist Z:\EFI\Microsoft\boot\BCD echo Warning: File \EFI\Microsoft\boot\BCD missing at EFI System Partition at GPT disk 0
 goto :SearchWindows
)

echo search file \boot\BCD
rem exclude X: and Y: Win10PESE (DVD) drive, 
rem assumption: first hit is the most likely one (default in front of media, PE assigns a low letter) , no validation
FOR %%w IN (C D E F G H I J K L N M O P Q R S T U V W Z) DO (
   if exist %%w:\boot\BCD set BootPartBIOS=%%w:& echo BootPartBIOS %%w &goto :SearchWindows
)

:SearchWindows
echo search file \Windows\system32\config\system
rem assumption: a low letter is the most likely one, validate numbers: multiboot
FOR %%w IN (Z W V U T S R Q P O N M L K J I H G F E D C) DO (
   if exist %%w:\Windows\system32\config\system set OSPART=%%w:& set /a CountOSPART+=1& echo OSPART %%w
)
if %CountOSPART% NEQ 1 (echo Error: %CountOSPART% OS partitions &pause &goto :eOf)


:DoInstall
echo. &echo to do: backup data
echo verify the backup data manually
pause

echo. &echo Apply a install.wim to %OSPART%
if DEFINED BootPartBIOS echo set BIOS or all boot environment to %BootPartBIOS%
if DEFINED BootPartEFI  echo set UEFI or all boot environment to %BootPartEFI%
This is a draft example, expect errors, to be tested and adjusted.
  • devdevadev likes this

#134 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 17 August 2017 - 11:23 PM

http://reboot.pro/to...e-2#entry188563

 

IC611726.gif

 

This is the only supported disk configuration for Windows To Go. With this disk configuration, a single Windows To Go drive can be booted on computers with UEFI and legacy BIOS firmware.

 

I know this configuration is for WTG. But Can someone (even myself) not utilize same in Disk 0 to support both UEFI and BIOS ? Will it also work in Disk 0 ?

 

AFAIK, This configuration does not utilizes c12a7328-f81f-11d2-ba4b-00a0c93ec93b GPT Partition but still support UEFI along with BIOS ? May  be your above code already support this configuration too ?



#135 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 18 August 2017 - 03:10 AM

:SearchWindows
echo search file \Windows\system32\config\system
rem assumption: a low letter is the most likely one, validate numbers: multiboot
FOR %%w IN (Z W V U T S R Q P O N M L K J I H G F E D C) DO (
   if exist %%w:\Windows\system32\config\system set OSPART=%%w:& set /a CountOSPART+=1& echo OSPART %%w
)
if %CountOSPART% NEQ 1 (echo Error: %CountOSPART% OS partitions &pause &goto :eOf)

That's really Nice. But I will prefer to support at least Dual Booting because I always install Dual boot in any system.

@echo OFF
pushd "%~dp0"
SETLOCAL ENABLEDELAYEDEXPANSION
SET OSPART=
SET OSPART1=
SET OSPART2=
SET OSPART3=
SET OSVER1=
SET OSVER2=
SET OSVER3=
SET Internal=
SET CountOSPART=0
set SIG=sigcheck.exe
if /i "%PROCESSOR_ARCHITECTURE%"=="AMD64"  set SIG=sigcheck64.exe

FOR /F "tokens=2 delims= " %%A IN ('^( echo SEL DISK 0^&echo LIST PAR^)^|diskpart^|FIND "Parti"^|FIND /V "."') DO (
FOR /F "delims=*" %%B IN ('^( echo SEL DISK 0^&echo SEL PAR %%A^&echo DET PAR^)^|diskpart^|FIND "*"') DO (
SET Line=%%B
IF NOT "!Line:~14,1!"==" " SET INTERNAL=!INTERNAL! !Line:~14,1!
)
)
SET INTERNAL

FOR %%w IN (%INTERNAL%) DO (
   if exist %%w:\Windows\system32\config\system set OSPART=%%w:& call :GETVER !OSPART!\WIndows\explorer.exe !OSPART!
)
goto :eof

SET OSPART
SET OSVER
PAUSE

:GETVER
SET /A Counter+=1
set OSPART%Counter%=%2
%SIG% /accepteula %1 | find "10.0"   > nul && set OSVER%Counter%=10
%SIG% /accepteula %1 | find "6.1."   > nul && set OSVER%Counter%=7
%SIG% /accepteula %1 | find "6.2.7"  > nul && set OSVER%Counter%=7
%SIG% /accepteula %1 | find "6.2.92" > nul && set OSVER%Counter%=8.1
%SIG% /accepteula %1 | find "6.3.96" > nul && set OSVER%Counter%=8.1
goto :EOF

I also want to set OSVER of each OS found ...Any better idea ? 



#136 cdob

cdob

    Gold Member

  • Expert
  • 1469 posts

Posted 18 August 2017 - 06:07 PM

With this disk configuration, a single Windows To Go drive can be booted on computers with UEFI and legacy BIOS firmware.
I know this configuration is for WTG.

Windows To Go is a special case. Some features are limited
https://technet.micr...y/jj592680.aspx

A regular windows expect a GPT disk at UEFI mode.
There are certain limitations at windows setup, sleep mode, windows update, repair install. E.g. Windows 8 setup won't finish at a MBR UEFI disk.
Don't use a internal windows MBR UEFI disk. This is asking for trouble.
No, the script dosn't support this.
Therefore try this at testing hardware manually, no scripting.


 

support at least Dual Booting

That's not a regular setup anymore, this is a exception

Bcdboot.exe adds data to a existing bcd file. Run bcdboot more times.
Call :DoInstall as a subroutine.
 
FOR %%w IN (%INTERNAL%) DO (
   if exist %%w:\Windows\system32\config\system set OSPART=%%w:& call :DoInstall
)
goto :eof


:DoInstall
echo backup and verify data first
echo OSPART %OSPART%
echo BootPartBIOS %BootPartBIOS%
echo BootPartEFI %BootPartEFI%
goto :eof


#137 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 20 August 2017 - 06:12 AM

C:\Users\Kdeva>fsutil volume diskfree C:
Total # of free bytes        : 5348855808
Total # of bytes             : 32767995904
Total # of avail free bytes  : 5348855808

I want to echo Total Capacity and Free Space of C: Drive. Following code works as expected. But what will be the best way to get Exact and Accurate size in GB ?

SET OSCAP=
SET OSFREE=
FOR /f "tokens=1*delims=:" %%i IN ('fsutil volume diskfree C:') DO (
    SET "disktotal=!diskavail!"
    SET "diskavail=%%j"
)
SET OSCAP=%disktotal:~0,-9%
SET OSFREE=%diskavail:~0,-9%

ECHO Total Capacity - %OSCAP% GB
ECHO     Free Space - %OSFREE% GB

Is it the best and simple way to get exact and accurate total size in GB ?

for /F "tokens=2 delims=:" %%a in ('fsutil volume diskfree C: ^| find /i "of bytes"') do set bytes=%%a
set /A OSCAP=%bytes:~0,-3%/1024*1000/1024/1024
echo Total Capacity= %OSCAP% GB

Any better LOGIC to do exactly the same ?



#138 paraglider

paraglider

    Gold Member

  • .script developer
  • 1743 posts
  • Location:NC,USA
  •  
    United States

Posted 20 August 2017 - 12:30 PM

Problem is a GB is 1024 * 1024 * 1024 not 1000000000. Unfortunately cmd.exe set /a only supports 32 bit integers not 64 bit integers. The integers you need to manipulate are much bigger than a 32 bit integer.

 

Look at this link for some ideas:

 

https://superuser.co...isk-space-in-gb

 

Took me 2 minutes using google to find that article.



#139 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 20 August 2017 - 01:20 PM

Took me 2 minutes using google to find that article.

i have already checked those ideas using difficult Power shell ? I am looking for simple and smallest code utilizing native tools that will also work in bare minimum WinPE ? BTW, Thanks for the hint...Finally I got the exact logic here..

https://stackoverflo...windows-c-drive

@echo off
setlocal ENABLEDELAYEDEXPANSION
SET OSCAP=
SET OSFREE=
FOR /f "tokens=1*delims=:" %%i IN ('fsutil volume diskfree C:') DO (
    SET "disktotal=!diskavail!"
    SET "diskavail=%%j"
)
SET /A OSCAP=%disktotal:~0,-3%/1024*1000/1024/1024
SET /A OSFREE=%diskavail:~0,-3%/1024*1000/1024/1024
ECHO Total Capacity= %OSCAP% GB     Free Space= %OSFREE% GB
pause
FOR /f "tokens=2*delims=:" %%i IN ('fsutil volume diskfree C:') DO (
 SET "disktotal=!diskavail!"
 SET "diskavail=%%i"
)
SET /A OSCAP=%disktotal:~0,-3%/1024*1000/1024/1024
SET /A OSFREE=%diskavail:~0,-3%/1024*1000/1024/1024

ECHO Total Capacity= %OSCAP% GB     Free Space= %OSFREE% GB
pause


#140 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 20 August 2017 - 02:52 PM

As it was said before, it doesn't makes much difference to use GiB or GB, and since GiB are much more easy to deal with (if some approximaton is allowed).

 

Should devadevadev choose the unneeded more complex way, he can peruse the batches here:

http://reboot.pro/to...and-hex2deccmd/

to make large multiplications and divisions in batch.

 

:duff:

Wonko



#141 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 20 August 2017 - 04:20 PM

In case script does not found any 'Boot Partition' and/or 'OS Partition' in Disk 0. Then most probably either of the following scenario definitely happen ?

1. There is a 'Boot Partition' along with a formatted  'OS Partition' at the starting of Disk0

2. There is a 'Boot Partition' along with a unallocated space at the starting of Disk0

3. There is a formatted partition at the starting of Disk0

4. There is a unallocated space at the starting of Disk0

 

As a common solution, I will first create a Primary Partition from unallocated space only if maximum allowed Primary partition not already created ? And then set drive letter of newly Created/Totally Empty primary partition to OSPART1. Then I will check if there is a 350 MB or lower primary partition exist ? Is so then set drive letter of newly created 'System Reserved' partition to SYSPART otherwise set SYSPART=%OSPART1%.



#142 paraglider

paraglider

    Gold Member

  • .script developer
  • 1743 posts
  • Location:NC,USA
  •  
    United States

Posted 21 August 2017 - 12:28 PM

Certainly under windows 10 there are some inconsistencies in how it displays volume sizes. According to fsutil my c: size = 209243336704 bytes. By my calculation this is 194.87GB. Disk management shows this as 194.87. Explorer / diskpart rounds down to 194. That would be ok but sometimes explorer does not round down so my external USB drive which has 2 volumes shows these as 48.8 GB and 398 GB where as disk management shows them as 48.83 GB or 48.81 depending on where you look and 398.30 GB ( size as reported by fsutil for first is 52414119936 which I think is 48.81 ).



#143 paraglider

paraglider

    Gold Member

  • .script developer
  • 1743 posts
  • Location:NC,USA
  •  
    United States

Posted 22 August 2017 - 02:33 AM

I wrote a little utility named togb.exe. Its downloadable from here as a winbuilder script:

 

https://paraglidernc...ies/togb.script

 

It will copy the utility to the windows\system32 directory

 

Its called like this:

 

togb 52427719168

 

It will output the value converted to GB or MB depending on parameter value. For the example it will output 48.83 GB to the console.


  • devdevadev likes this

#144 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 22 August 2017 - 11:39 AM

And in case of need (shameless plug ;)):

http://reboot.pro/to...elease-unwbzip/

 

 

The poor peeps running Windows XP will need to edit (with CFF explorer or similar) the MajorOperatingSystemVersion and MajorSubsystemVerion form 0006 to 0005, after which it works nicely.

Remember to thank the good MS guys for having made the 0006 version "default" in the compiler settings.

 

@Paraglider

With all due respect :), it makes little sense to have the program "automagically" decide the unit of measure, the result will be different (and thus not comparable) when you want to actually compare two very different values, or when one of the two is just below the threshold, I woould have expected something like 1023.999, however:



C:\>togb 1073741823
1023.100 MB

C:\>togb 1073741824
1 GB

It would be better if you made one that always converts to Gb, and one that always converts to Mb (or add a switch to "force" the one or the other".

 

BTW :w00t::



C:\>togb helloparaglider
5771126.24 GB

C:\>togb IamWonkotheSane
2845747.96 GB

togb without arguments just crashes, and togb /? outputs 0 MB

 

:duff:

Wonko



#145 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 22 August 2017 - 07:09 PM

 Any better idea for following approach ? Is it possible to use DISKPART code instead of following PartAssist code ?

@ECHO on
SETLOCAL ENABLEDELAYEDEXPANSION

if "!OSPART1!"=="" goto :UNALLOC
:OSINSTALL
PAUSE

:UNALLOC
FOR /F "tokens=*" %%A IN ('ECHO LIST VOLUME ^| DISKPART ^|FIND "Partition       0 B  No Media"') DO (
FOR /F "tokens=*" %%B IN ('^( ECHO LIST DISK^)^|DISKPART^|FIND "Disk 0"') DO (
SET Line=%%B
SET Unallocated=!Line:~33,5!
SET Unallocated=!Unallocated: =!
SET TotalSize=!Line:~24,5!
SET TotalSize=!TotalSize: =!
IF !Unallocated! EQU !TotalSize! goto :REPARTITION
IF "!Line:~39,2!"=="GB" IF !Unallocated! GTR 30 goto :CREATEPTN
)
)
goto :VIRGINPTN

:CREATEPTN
set FORMAT=ntfs
if "%Disk%"=="GPT" set FORMAT=fat32
if "!SYSPART!"=="" partassist.exe /hd:0 /cre /pri /size:350 /fs:%FORMAT% /align /label:System Reserved /letter:Z& SET SYSPART=Z:
partassist.exe /hd:0 /cre /pri /size:auto /fs:ntfs /act /align /label:Windows /letter:W& SET OSPART1=W:
goto :OSINSTALL

:REPARTITION
wpeutil UpdateBootInfo > nul
for /f "tokens=2* delims= 	" %%A in ('reg query HKLM\System\CurrentControlSet\Control /v PEFirmwareType') DO SET Firmware=%%B
:: Note: delims is a TAB followed by a space.
if %Firmware%==0x1 diskpart /s %PTN2%\WinNTSetup3\Tools\diskpart\SMART_BIOS_Setup.scr
if %Firmware%==0x2 diskpart /s %PTN2%\WinNTSetup3\Tools\diskpart\SMART_UEFI_Setup.scr
SET SYSPART=Z:
SET OSPART1=W:
SET OSPART2=V:
goto :OSINSTALL

:VIRGINPTN
FOR %%A IN (%INTERNAL%) DO (
FOR /f "tokens=2*delims=:" %%B IN ('fsutil volume diskfree %%A') DO (
 SET "disktotal=!diskavail!"
 SET "diskavail=%%B"
)
 SET /A "disktotal=!disktotal:~0,-3!/1024*1000/1024"
 SET /A "diskavail=!diskavail:~0,-3!/1024*1000/1024"
 SET /A "diskused=!disktotal!-!diskavail!"
 SET /A "disktotal=!disktotal!/1024"
 SET /A "diskavail=!diskavail!/1024"
 SET /A "disk0minusvirgin=!TotalSize!-!diskavail!" 
 ECHO TOTAL= !disktotal! GB
 ECHO FREE= !diskavail! GB
 ECHO USED= !diskused! MB
 ECHO DISK 0 TOTAL CAPACITY= !TotalSize! GB
 if !disk0minusvirgin! LSS 2 goto :REPARTITION
 if !diskused! LSS 2 if !disktotal! GTR 30 if "!SYSPART!"=="" set SYSPART=%%A
 if !diskused! LSS 2 if !disktotal! GTR 30 set OSPART1=%%A& goto:OSINSTALL
)
goto :EOF

Is there any missing scenario which I can also consider ?



#146 paraglider

paraglider

    Gold Member

  • .script developer
  • 1743 posts
  • Location:NC,USA
  •  
    United States

Posted 23 August 2017 - 06:18 AM

Purpose of togb was to display a disksize in a similar way to explorer / diskmanagement. Yes I could have added some error checking but did not seem to be any point for a small single purpose utility.



#147 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 23 August 2017 - 09:09 AM

Purpose of togb was to display a disksize in a similar way to explorer / diskmanagement. 

I understand, still it makes little sense (to me) to have a tool that decides itself what format to output.

The 1023.100 for 1073741823 remains "queer".

 

:duff:

Wonko



#148 devdevadev

devdevadev

    Silver Member

  • Advanced user
  • 540 posts
  •  
    India

Posted 02 May 2022 - 02:48 PM

Hi..Wonko..

 

Following code was working fine in Win 10 but in Win 11 it does not seems to work as expected. It's looking fsutil command show different output in Win 11. Following code also does not show correct MostFreeRem ? It show G: as most free Removalbe volume while E: have most free space. Volume G: is a FAT16 partition, Maybe it's why fsutil output is a bit different and spoil output.

 

Please help so following code will work correctly for Win 11 also...

@ECHO OFF
setlocal EnableDelayedExpansion

SET Partition=
SET Removable=
FOR /F "tokens=*" %%A IN ('ECHO LIST VOLUME ^| DISKPART ^|FIND "Healthy" ^|FIND "NTFS"') DO CALL :parse_volumes %%A
SET EXCLUDEDRIVES=%SYSPART%  %SYSPART11% %SystemDrive%
FOR %%A in (%EXCLUDEDRIVES%) DO SET Partition=!Partition:%%A =!
SET Partition
SET Removable

FOR %%A IN (%Partition% %Removable%) DO (
FOR /F "skip=2 tokens=2 delims=:" %%B IN ('fsutil volume diskfree %%A') DO (
ECHO %%A %%B
SET Vol_%%A=%%B
)
)

FOR %%A IN (%Partition%) DO CALL :Sort_Pval %%A !VOL_%%A!
FOR /F "tokens=2 Delims==" %%A IN ('SET PFree_') DO SET MostFreePart=%%A
SET MostFreePartMB=!VOL_%MostFreePart%!
SET MostFreePartMB=%MostFreePartMB: =%
SET MostFreePartMB=%MostFreePartMB:~0,-6%
SET MostFreePart

FOR %%A IN (%Removable%) DO CALL :Sort_Rval %%A !VOL_%%A!
FOR /F "tokens=2 Delims==" %%A IN ('SET RFree_') DO SET MostFreeRem=%%A
SET MostFreeRemMB=!VOL_%MostFreeRem%!
SET MostFreeRemMB=%MostFreeRemMB: =%
SET MostFreeRemMB=%MostFreeRemMB:~0,-6%
SET MostFreeRem
PAUSE




:Sort_Pval
SET Num=0000000000000%2
SET Num=%Num:~-14,14%
SET PFree_%Num%=%1
GOTO :EOF 

:Sort_Rval
SET Num=0000000000000%2
SET Num=%Num:~-14,14%
SET RFree_%Num%=%1
GOTO :EOF

:parse_volumes
SET Line=%*
IF NOT "%Line:~13,1%"==" " SET %Line:~37,9%=!%Line:~37,9%! %Line:~13,1%:
GOTO :EOF

Output -

Partition= C:
Removable= E: G:
C:   4,75,57,75,488 ( 4.4 GB)
E:   1,89,62,02,240 ( 1.8 GB)
G:  10,28,096 (1004.0 KB)
G:   1,26,976 ( 124.0 KB)
MostFreePart=C:
MostFreePartMB=4,75,57,75,488(
MostFreeRem=G:
MostFreeRemMB=1,26,976(12
Press any key to continue . . .

Regards....







Also tagged with one or more of these keywords: cmd, winpe, boot.wim, usb booting, multibooting

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users