doestergaard Posted January 13, 2015 Share Posted January 13, 2015 This is a tough one and I hope some of you guys can help me out. I need to know the disk & partition index numbers from a partition which has Windows installed. The script will search for the Windows folder and retrieve its drive letter. I just don't how to manage this. I have tried WMI, but seems tricky and not what im after. Any help is appreciated! Thanks in advance Link to comment Share on other sites More sharing options...
water Posted January 13, 2015 Share Posted January 13, 2015 Did you search the forum? I know this has already been discussed. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted January 13, 2015 Share Posted January 13, 2015 How about >this thread? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
doestergaard Posted January 13, 2015 Author Share Posted January 13, 2015 Yes i did, but as far as I can tell it only shows how to get the drive letter only, i need the disk number and partition number FROM a driver letter, for instance: Drive C: is on disk 0 partition 2 Link to comment Share on other sites More sharing options...
water Posted January 13, 2015 Share Posted January 13, 2015 When running this script (generated by the AutoIt tool ScriptoMatic) do you get the correct result? ; Generated by AutoIt Scriptomatic $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $Output="" $Output = $Output & "Computer: " & $strComputer & @CRLF $Output = $Output & "==========================================" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDiskToPartition", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $Output = $Output & "Antecedent: " & $objItem.Antecedent & @CRLF $Output = $Output & "Dependent: " & $objItem.Dependent & @CRLF $Output = $Output & "EndingAddress: " & $objItem.EndingAddress & @CRLF $Output = $Output & "StartingAddress: " & $objItem.StartingAddress & @CRLF if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop $Output="" Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_LogicalDiskToPartition" ) Endif My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
doestergaard Posted January 13, 2015 Author Share Posted January 13, 2015 Yes But how does it know its drive C? Thank you very much for your help! Really appreciate it Link to comment Share on other sites More sharing options...
water Posted January 13, 2015 Share Posted January 13, 2015 Because the driver letter is part of $obj.Dependent My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted January 13, 2015 Share Posted January 13, 2015 This should display a MsgBox for all drives displaying disk # and partition #. $objWMIService = ObjGet("winmgmts:\\.\root\CIMV2") $WMIQuery = $objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDiskToPartition") For $obj In $WMIQuery $sAntecedent = $obj.Antecedent $sDependent = $obj.Dependent $iDisk = StringMid($sAntecedent, StringInStr($sAntecedent, "Disk #") + 6, 1) $iPartitiion = StringMid($sAntecedent, StringInStr($sAntecedent, "Partition #") + 11, 1) $sDrive = StringMid($sDependent, StringInStr($sDependent, 'DeviceID="') + 10, 1) MsgBox(0, $sDrive & " Drive", $sDrive & " Drive is on Disk #" & $iDisk & ", partition #" & $iPartitiion) Next Works for one digit disk # and partition #. doestergaard 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
doestergaard Posted January 13, 2015 Author Share Posted January 13, 2015 Holy, sh*t! Thanks! You are mig hero Just a final question. I will only need the integer for Building a diskpart script for Windows PE. The above code will detect the Windows partition yes? Once Again, thank you very much!! Link to comment Share on other sites More sharing options...
water Posted January 13, 2015 Share Posted January 13, 2015 Full description of the Win32_LogicalDiskToPartition class can be found here. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
doestergaard Posted January 13, 2015 Author Share Posted January 13, 2015 Whoops, sry, it only gives back the int, thanks! Link to comment Share on other sites More sharing options...
doestergaard Posted January 13, 2015 Author Share Posted January 13, 2015 (edited) One more thing. Diskpart says that drive C has partition number 2 The result i get from your code is 1 Edited January 13, 2015 by doestergaard Link to comment Share on other sites More sharing options...
water Posted January 13, 2015 Share Posted January 13, 2015 What does the Windows Device Manager display? I'm running Windows in a VM and get partition number 1 because partition 0 is used by Windows itself. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki 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