Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Enumerate hard disks, exclude partitions
#31
you don't need the batch file at all stop using it and use a txt file like i showed you

the only reason we are using a txt file is that is how you do multiple commands in diskpart but a Batch file is not needed at all  for qm

this function shows  all drives not just hd's


Code:
Copy      Help
dll kernel32 #GetLogicalDrives
dll kernel32 #GetDriveType $nDrive
int i dt dm
str s(" :\") s2
dm=GetLogicalDrives ;;32-bit mask of available drives
for i 0 32
,if(dm>>i&1)
,,s[0]='A'+i
,,dt=GetDriveType(s); if(dt>6) dt=0
,,s2.getl("UNKNOWN[]NO_ROOT_DIR[]REMOVABLE[]FIXED[]REMOTE[]CDROM[]RAMDISK" dt)
,,out "%s %s" s s2

or here is a c# function tht will pretty much give you all the info on all your drives uses wmi
would need to simply this as there is way more info than you need


Function GetDriveAndPartitionInfoWMI 
Code:
Copy      Help
str code=
;using System;
;using System.Management;
;using System.Windows.Forms;
;namespace WMISample
;{
;;;;public class MyWMIQuery
;;;;{
;;;;;;;;public static void Main()
;;;;;;;;{
;;;;;;;;;;;;try
;;;;;;;;;;;;{
;;;;;;;;;;;;;;;;ManagementObjectSearcher searcher =
;;;;;;;;;;;;;;;;;;;;new ManagementObjectSearcher("root\\CIMV2",
;;;;;;;;;;;;;;;;;;;;"SELECT * FROM Win32_DiskPartition");
;;;;;;;;;;;;;;;;foreach (ManagementObject queryObj in searcher.Get())
;;;;;;;;;;;;;;;;{
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("-----------------------------------");
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("Win32_DiskPartition instance");
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("-----------------------------------");
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("Access: {0}", queryObj["Access"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("Availability: {0}", queryObj["Availability"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("BlockSize: {0}", queryObj["BlockSize"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("Bootable: {0}", queryObj["Bootable"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("BootPartition: {0}", queryObj["BootPartition"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("Caption: {0}", queryObj["Caption"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("ConfigManagerErrorCode: {0}", queryObj["ConfigManagerErrorCode"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("ConfigManagerUserConfig: {0}", queryObj["ConfigManagerUserConfig"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("CreationClassName: {0}", queryObj["CreationClassName"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("Description: {0}", queryObj["Description"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("DeviceID: {0}", queryObj["DeviceID"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("DiskIndex: {0}", queryObj["DiskIndex"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("ErrorCleared: {0}", queryObj["ErrorCleared"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("ErrorDescription: {0}", queryObj["ErrorDescription"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("ErrorMethodology: {0}", queryObj["ErrorMethodology"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("HiddenSectors: {0}", queryObj["HiddenSectors"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("Index: {0}", queryObj["Index"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("InstallDate: {0}", queryObj["InstallDate"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("LastErrorCode: {0}", queryObj["LastErrorCode"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("Name: {0}", queryObj["Name"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("NumberOfBlocks: {0}", queryObj["NumberOfBlocks"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("PNPDeviceID: {0}", queryObj["PNPDeviceID"]);
;;;;;;;;;;;;;;;;;;;;if(queryObj["PowerManagementCapabilities"] == null)
;;;;;;;;;;;;;;;;;;;;;;;;Console.WriteLine("PowerManagementCapabilities: {0}", queryObj["PowerManagementCapabilities"]);
;;;;;;;;;;;;;;;;;;;;else
;;;;;;;;;;;;;;;;;;;;{
;;;;;;;;;;;;;;;;;;;;;;;;UInt16[] arrPowerManagementCapabilities = (UInt16[])(queryObj["PowerManagementCapabilities"]);
;;;;;;;;;;;;;;;;;;;;;;;;foreach (UInt16 arrValue in arrPowerManagementCapabilities)
;;;;;;;;;;;;;;;;;;;;;;;;{
;;;;;;;;;;;;;;;;;;;;;;;;;;;;Console.WriteLine("PowerManagementCapabilities: {0}", arrValue);
;;;;;;;;;;;;;;;;;;;;;;;;}
;;;;;;;;;;;;;;;;;;;;}
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("PowerManagementSupported: {0}", queryObj["PowerManagementSupported"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("PrimaryPartition: {0}", queryObj["PrimaryPartition"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("Purpose: {0}", queryObj["Purpose"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("RewritePartition: {0}", queryObj["RewritePartition"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("Size: {0}", queryObj["Size"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("StartingOffset: {0}", queryObj["StartingOffset"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("Status: {0}", queryObj["Status"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("StatusInfo: {0}", queryObj["StatusInfo"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("SystemCreationClassName: {0}", queryObj["SystemCreationClassName"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("SystemName: {0}", queryObj["SystemName"]);
;;;;;;;;;;;;;;;;;;;;Console.WriteLine("Type: {0}", queryObj["Type"]);
;;;;;;;;;;;;;;;;}
;;;;;;;;;;;;}
;;;;;;;;;;;;catch (ManagementException e)
;;;;;;;;;;;;{
;;;;;;;;;;;;;;;;MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
;;;;;;;;;;;;}
;;;;;;;;}
;;;;}
;}
CsExec(code)
#32
I am looking for a simpler way to achieve my needs. Smile

I can also use QM recording to achieve my needs, but sometimes it is not accurate enough.
#33
@kevin 

The above C# code will prompt an error under the winpe system.

I have not found a more effective method at the moment. Confused
————————————————————————————————————————————————————————————

Error (RT) in <open ":1582: /4433">Macro2:  failed to initialize. Must be installed .NET framework version 4.x or 3.5.    d=1.    <help #IDP_ERR>?
#34
need to install .NET framework
#35
The PE system I use is generally without the .net framework. I usually maintain the system.

Is there any good way to extract complete hard drive information? Huh

I need to get three pieces of information:

1. How many physical hard disks are there? What type of hard disk partition is (MBR or GPT)

2. If it is a GPT type hard disk partition, what is the serial number of the ESP partition?

3. Information about all partitions on each physical hard disk, including hidden partitions(Currently only the diskpart command can display hidden partition information.)
——————————————————————————————————————————
For example the picture below:

1. There are 2 disks, the disk 0 partition type is GPT, and the disk 1 partition type is MBR.

2. Disk 0, ESP partition number is 1

I found a very powerful batch file to get the hard drive information, Smile  but I don't know how to extract the useful code inside.


Attached Files Image(s)
   

.zip   DP_script.zip (Size: 12.3 KB / Downloads: 262)
#36
Double-click the DP_script-X9.12.8-En.cmd file to generate a temp folder (the image below), which contains the generated disk and partition information, how to extract the DP_script-X9.12.8-En.cmd file Related code, directly related to the information?


Attached Files Image(s)
   
#37
I use the following VBS code to get the hard drive information, suggesting an error, but I can run the VBS code directly and it is successful. Huh


Macro HD vbs
Code:
Copy      Help
str vbs=
;Set ws = CreateObject("Wscript.Shell")
;Set fso = CreateObject("Scripting.FileSystemObject")
;
;If LCase(Right(WSH.FullName, 11)) = "wscript.exe" Then
;;;;;ws.run "cscript.exe -nologo """ & WSH.ScriptFullName & """", 0
;;;;;WSH.Quit
;End If
;
;Dim arr()
;Set oExec = ws.Exec("cmd /c ""(echo;list disk|diskpart)|findstr /irc:""[0-9][0-9]*  *[tgmk]b"" "" ")
;
;Do While oExec.StdOut.AtEndOfStream <> true
;;;;;str = Trim(oExec.StdOut.ReadLine)
;;;;;num = CInt(Split(str, " ")(1))
;;;;;ReDim Preserve arr(num)
;;;;;If InStrRev(str, "*") >0 Then
;;;;;;;;;arr(num) = "GPT"
;;;;;Else
;;;;;;;;;arr(num) = "MBR"
;;;;;End If
;Loop
;
;Dim objWMI, colDisks
;Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
;Set colDisks = objWMI.ExecQuery("select * from Win32_DiskDrive where MediaType like 'fixed%'")
;For Each objDisk in colDisks
;;;;;s = s & "Disk" & objDisk.Index & ":" & vbTab
;;;;;s = s & "size:" & GetSize(objDisk.Size) & vbTab
;;;;;s = s & "type:" & objDisk.Caption & vbTab
;;;;;s = s & "Partition Table:" & arr(CInt(objDisk.Index)) & vbCrLf
;;;;;strDiskID = Replace(objDisk.DeviceID, "\", "\\")
;;;;;Set colPartitions = objWMI.ExecQuery _
;;;;;;;;;("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & strDiskID & """}" _
;;;;;;;;;& " where AssocClass=Win32_DiskDriveToDiskPartition")
;;;;;For Each objPartition in colPartitions
;;;;;;;strPartId = objPartition.DeviceID
;;;;;;;Set colLogicalDisks = objWMI.ExecQuery _
;;;;;;;;;;;("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & strPartId & """}  where AssocClass=Win32_LogicalDiskToPartition")
;;;;;;;For Each objLogicalDisk in colLogicalDisks
;;;;;;;;;size = objLogicalDisk.Size
;;;;;;;;;free = objLogicalDisk.Freespace
;;;;;;;;;used = FormatNumber((size - free) / size * 100, 2, true) & "%"
;;;;;;;;;s = s & "Partition" & objLogicalDisk.DeviceID & vbTab
;;;;;;;;;s = s & "size:" & GetSize(size) & vbTab
;;;;;;;;;s = s & "Remaining:" & GetSize(free) & vbTab
;;;;;;;;;s = s & "Usage rate:" & used & vbCrLf
;;;;;;;Next
;;;;;Next
;;;;;s = s & vbCrLf
;Next
;Msgbox s
;
;
;Function GetSize(intSize)
;;;If intSize/1024/1024 > 1024 Then
;;;;;GetSize = FormatNumber(intSize/1024/1024/1024, 2, true) & "GB"
;;;Else
;;;;;GetSize = FormatNumber(intSize/1024/1024, 2, true) & "MB"
;;;End If
;End Function

VbsExec vbs


Forum Jump:


Users browsing this thread: 1 Guest(s)