Jump to content

Get drive partitons info


Recommended Posts

Good day.

I am looking for a way to get the drives start lba and sectors and also partition type

 

Here is what I found but I still need the partition type and start lba

strComputer = "."Set objWMIService = GetObject("winmgmts:" _    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colDiskPartitions = objWMIService.ExecQuery _    ("Select * from Win32_DiskPartition")For each objPartition in colDiskPartitionsif objPartition.DiskIndex = 3 then           Wscript.Echo "Disk Index: " & objPartition.DiskIndex     Wscript.Echo "Device ID: " & objPartition.DeviceID      Wscript.Echo "Block Size: " & objPartition.BlockSize         Wscript.Echo "Bootable: " & objPartition.Bootable     Wscript.Echo "Boot Partition: " & objPartition.BootPartition    Wscript.Echo "Description: " & objPartition.Description      Wscript.Echo "Index: " & objPartition.Index           Wscript.Echo "Name: " & objPartition.Name     Wscript.Echo "Number Of Blocks: " & _        objPartition.NumberOfBlocks         Wscript.Echo "Primary Partition: " & _        objPartition.PrimaryPartition       Wscript.Echo "Size: " & objPartition.Size     Wscript.Echo "Starting Offset: " & _        objPartition.StartingOffset         Wscript.Echo "Type: " & objPartition.Type End if	Next

Please help me because the info is needed so that it can be writen to a file

Link to comment
Share on other sites


I don't get it. :unsure:

 

How EXACTLY are you running that snippet?

WHAT (EXACTLY) does it output?

 

The partition starting offset is actually the "start lba".

 

Filesystem type cannot be anyway determined by the partition ID, the partition ID (though this has not been clear for years) is only a "protective ID".

 

Right now a partition ID of 07 may mean - besides HPFS - both NTFS or exFAT so it is pretty much meaningless :ph34r:.

 

I suspect that this thread is more or less directly connected to this one:

http://www.msfn.org/board/topic/174825-get-disk-number-from-drive-letter-in-cmd/

 

maybe - just maybe - if you can provide a general idea of the context and your expected final goal there could be other, better or faster (or both) ways, as always I may well be wrong :w00t: , but I have *somehow* the feeling that you are trying to reinvent the wheel, one spoke at the time ....

 

jaclaz

Link to comment
Share on other sites

No it doesn't it has to do with this post http://www.msfn.org/board/topic/174281-grub4dos-backup-and-restore-partion-table-with-a-script/?p=1106522

I see why the start LBA I was getting froom bootice and the starting offset I got from the vbs do not match. I have do something like this:

strComputer = "."Set objWMIService = GetObject("winmgmts:" _    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colDiskPartitions = objWMIService.ExecQuery _    ("Select * from Win32_DiskPartition")For each objPartition in colDiskPartitionsif objPartition.DiskIndex = 2 then    Wscript.Echo "Device ID: " & objPartition.DeviceID      strBlockSize = objPartition.BlockSize    strNumberBlocks = objPartition.StartingOffset    strStartLBA = strNumberBlocks/strBlockSizeWscript.Echo "partnew (hd" & objPartition.DiskIndex & "," & objPartition.Index & ")" & " 0x0B " & strStartLBA & " " & objPartition.NumberOfBlocksEnd ifNext'Fixed it sorry used wrong stuff

But how do I do it for each partition?

Edited by silent001
Link to comment
Share on other sites

Well, again, if you explain WHAT you actually *need* and WHY you *need* it, there may be "better" ways.

 

Also, what you posted is a snippet, as asked before, can you post the actual .vbs EXACTLY as you run it (AND post information on how exactly are you running it)?

 

However this:

strStartLBA = strNumberBlocks/strBlockSize

 

doesn't sound right.

 

You get the StartingOffset (in bytes) and divide it by blocksize to get StartingLBA (in sectors or blocks) and of course you get size (in bytes) and divide it by blocksize to get size (in blocks).

 

jaclaz

Link to comment
Share on other sites

I am trying to get the start LBA and number of blocks and ID so I can write it to my menu.lst for grub4dos so that it writes in the following format

root (hd0,0)partnew (hd0,0) 0x0B 95674368 29358080                #ID  #STARTLBA #NumberOfBlockschainloader (hd0)+1boot

I want it to dedect each partitions info as it does, set it as a veriable so I can write it the menu.lst for my grub4dos

Edited by silent001
Link to comment
Share on other sites

Here is what I have so far

Dim objFSO,objFile,strCD,strScript,outFileRunAsAdmin()strComputer = "."Set objFSO=CreateObject("Scripting.FileSystemObject")strScript = WScript.ScriptFullNamestrCD = objFSO.GetParentFolderName(strScript)outFile = strCD & "\temp.txt"Set objFile = objFSO.CreateTextFile(outFile,True)Set objWMIService = GetObject("winmgmts:" _    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colDiskPartitions = objWMIService.ExecQuery _    ("Select * from Win32_DiskPartition")For each objPartition in colDiskPartitionsif objPartition.DiskIndex = 2 then    Wscript.Echo "Device ID: " & objPartition.DeviceID      strBlockSize = objPartition.BlockSize    strNumberBlocks = objPartition.StartingOffset    strStartLBA = strNumberBlocks/strBlockSize'Wscript.Echo "partnew (hd" & objPartition.DiskIndex & "," & objPartition.Index & ")" & " 0x0B " & strStartLBA & " " & objPartition.NumberOfBlocksobjFile.Write "partnew (hd" & objPartition.DiskIndex & "," & objPartition.Index & ")" & " 0x0B " & strStartLBA & " " & objPartition.NumberOfBlocks & vbCrLf & vbCrLfEnd ifNextobjFile.Close'Fixed it sorry used wrong stuff''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Function RunAsAdmin()Dim objAPPIf WScript.Arguments.length = 0 ThenSet objAPP = CreateObject("Shell.Application")objAPP.ShellExecute "wscript.exe", """" & _WScript.ScriptFullName & """" & " RunAsAdministrator",,"runas", 1WScript.QuitEnd IfEnd function

Does this seam right?

Edited by silent001
Link to comment
Share on other sites

Does this seam right?

I don't know. :unsure:

At first sight it seems (to me) more complex than needed.

Maybe you could try starting from a "simpler" base *like*:

 On Error Resume NextConst wbemFlagReturnImmediately = &h10Const wbemFlagForwardOnly = &h20strComputer = "."WScript.EchoWScript.Echo "=========================================="WScript.Echo "Computer: " & strComputerWScript.Echo "=========================================="Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_DiskPartition", "WQL", _wbemFlagReturnImmediately + wbemFlagForwardOnly)For Each objItem In colItemsWScript.Echo "DeviceID: " & objItem.DeviceIDStartLBA = Int(objItem.StartingOffset/objItem.BlockSize)NumSectors=Int(objItem.Size/objItem.BlockSize)WScript.Echo "StartLBA: " & StartLBAWScript.Echo "NumSectors: " & NumSectorsWScript.EchoNext

jaclaz

Edited by jaclaz
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...