I've progressed this much with my effort, i don't know if there's any
mistake in batch syntax as well as logic. But i couldn't advance
beyond. I've one physical disk currently and it has 4 primary
partitions, out of which partition 2 is currently active and i'm
posting here by booting my XP into Partition 1. I've windows xp
installed in both partition 1 and 2.
My progress:
@echo Off
setlocal
If exist partinfocmd.bat del /q /f partinfocmd.bat
echo list disk > disklist.txt
diskpart /s disklist.txt >> diskdata.log
for /f "tokens=1-4 skip=8" %%B in (diskdata.log) do (
set DisknuM=%%C
echo select disk %%C > gpartcfg.txt
echo list part >> gpartcfg.txt
echo diskpart /s gpartcfg.txt ^> gpartcfg.log >> partinfocmd.bat
)
call partinfocmd.bat
for /f "tokens=1-4 skip=8" %%B in (diskdata.log) do (
@for /f "tokens=1-8 skip=10" %%O in (gpartcfg.log) do (
echo select disk %%C
echo select part %%P
echo detail part
)
)> partstat.txt
****************************************************************************
Now partstat.txt contains following:
select disk 0
select part 1
detail part
select disk 0
select part 2
detail part
select disk 0
select part 3
detail part
select disk 0
select part 4
detail part
****************************************************************************
I'm unable to parse output of diskpart /s partstat.txt.
Please help.
>)> partstat.txt
>****************************************************************************
>Now partstat.txt contains following:
>select disk 0
>select part 1
>detail part
>select disk 0
>select part 2
>detail part
>select disk 0
>select part 3
>detail part
>select disk 0
>select part 4
>detail part
>****************************************************************************
>I'm unable to parse output of diskpart /s partstat.txt.
If you shows us the output and what you want to extract then it might be
easier...
This is the output of diskpart /s partstat.txt >>partstat.log
***********************************************************************************************
Microsoft DiskPart version 5.1.3565
Copyright (C) 1999-2003 Microsoft Corporation.
On computer: XP-205284056
Disk 0 is now the selected disk.
Partition 1 is now the selected partition.
Partition 1
Type : 07
Hidden: No
Active: No
Volume ### Ltr Label Fs Type Size Status
Info
---------- --- ----------- ----- ---------- ------- ---------
--------
* Volume 2 C XPSP3_UA NTFS Partition 78 GB Healthy
Boot
Disk 0 is now the selected disk.
Partition 2 is now the selected partition.
Partition 2
Type : 07
Hidden: No
Active: Yes
Volume ### Ltr Label Fs Type Size Status
Info
---------- --- ----------- ----- ---------- ------- ---------
--------
* Volume 3 D NTFS Partition 78 GB Healthy
System
Disk 0 is now the selected disk.
Partition 3 is now the selected partition.
Partition 3
Type : 07
Hidden: No
Active: No
Volume ### Ltr Label Fs Type Size Status
Info
---------- --- ----------- ----- ---------- ------- ---------
--------
* Volume 4 K SATA_III NTFS Partition 155 GB
Healthy
Disk 0 is now the selected disk.
Partition 4 is now the selected partition.
Partition 4
Type : 07
Hidden: No
Active: No
Volume ### Ltr Label Fs Type Size Status
Info
---------- --- ----------- ----- ---------- ------- ---------
--------
* Volume 5 L SATA_IV NTFS Partition 155 GB
Healthy
***********************************************************************************************
In this output only in case of Partition 2 there is an output called
Active: Yes, while in case of other partitions the result is Active:
No. I need to know the Partition No. firstly, then correlate that no.
with Drive Letter Assigned to it.
thanks foxidrive.
AFAIK the active Partion is always C in DOS - XP. (I don't know Vista)
as to which partion number this is, I don't know.
Here's an idea:
list the partitions, then do for each Primary (only these can be active I
believe)
select the partion and detail it to a temp file, Find "Active: Yes". if so
you have your Active Partition.
I had to force the disk admin service to start each time - I don't know
why. This slows it down considerably.
@echo off
echo select disk 0 >~dpa.txt
echo list part >>~dpa.txt
net start dmadmin >nul
diskpart /s ~dpa.txt >~dpb.txt
for /f "skip=9 tokens=2,3" %%A in (~dpb.txt) do if /%%B/==/Primary/ call
:chkpri %%A
rem del ~dp?.txt
goto :eof
:chkpri
echo select disk 0 >~dpx.txt
echo select part %1 >>~dpx.txt
echo detail part >>~dpx.txt
net start dmadmin >nul
diskpart /s ~dpx.txt >~dp%1.txt
find "Active: Yes" <~dp%1.txt>nul
if not errorlevel 1 echo Active Partition is %1
--
Siggy played guitar
>> If you shows us the output and what you want to extract then it might be
>> easier...
>
>This is the output of diskpart /s partstat.txt >>partstat.log
@echo off
for /f "tokens=1,2,4" %%a in (
'type "partstat.log"^|findstr /c:"Active: Yes" /c:"* Volume"'
) do (
if defined active if not defined drv if "%%a"=="*" set drv=%%c:
if "%%b"=="Yes" set active=YES
)
echo active partition is %drv% and status is %active%
pause