silent001 Posted November 30, 2015 Share Posted November 30, 2015 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 lbastrComputer = "."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 NextPlease help me because the info is needed so that it can be writen to a file Link to comment Share on other sites More sharing options...
jaclaz Posted November 30, 2015 Share Posted November 30, 2015 I don't get it. 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 . 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 , 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 More sharing options...
silent001 Posted December 1, 2015 Author Share Posted December 1, 2015 (edited) 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=1106522I 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 stuffBut how do I do it for each partition? Edited December 1, 2015 by silent001 Link to comment Share on other sites More sharing options...
jaclaz Posted December 1, 2015 Share Posted December 1, 2015 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 More sharing options...
silent001 Posted December 1, 2015 Author Share Posted December 1, 2015 (edited) 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 formatroot (hd0,0)partnew (hd0,0) 0x0B 95674368 29358080 #ID #STARTLBA #NumberOfBlockschainloader (hd0)+1bootI 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 December 1, 2015 by silent001 Link to comment Share on other sites More sharing options...
silent001 Posted December 1, 2015 Author Share Posted December 1, 2015 (edited) Here is what I have so farDim 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 functionDoes this seam right? Edited December 1, 2015 by silent001 Link to comment Share on other sites More sharing options...
jaclaz Posted December 1, 2015 Share Posted December 1, 2015 (edited) Does this seam right?I don't know. 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.EchoNextjaclaz Edited December 1, 2015 by jaclaz Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now