CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    894

    How to tell if Windows partition is active?

    My goal is to know if Windows is installed on an active disk partition. Any ideas?

  2. #2
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: How to tell if Windows partition is active?

    From within Windows?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: How to tell if Windows partition is active?

    From within windows: may not even be possible depending on what sort of raw access you get to the partition information. On a typical windows, you can't access this other than writing a kernel disk driver.

    if outside of windows. "It depends". Do you only care about MBR based partitioning or do you also need to support other partitioning schemes like EFI, GPT, MIX ?

    Do you care about bootmenu's that boot the PC into a menu, then allow you to launch your OS even from non-active partitions or even logical partitions insife an extended partition (on MBR).
    The concept of "active partition" kinda means you 're asking about MBR because other schemes have other terminilogy or maybe even no such concept as "active partition" at all.

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    894

    Re: How to tell if Windows partition is active?

    Hmm. Good points guys. And yes, I do need it from within Windows. In other words, my app needs to know if the Windows it runs under is installed on an active partition. (And to OReubens's point, I'll be honest with you, I'm not very well versed in the subject of disk partitions, but from what I understand after reading about the subject, I do need it for the Master boot record.)

    Let me explain. The reason I need to know this, is to diagnose an issue with workstations not being able to enter sleep mode if Windows is not installed on an active partition. (The real issue in this case probably lies within the chipset driver, but since I do not have direct access to the driver(s) that may be installed on those workstations, a quick workaround of making a partition active seems to solve the issue. In my case I need to know this from a user-mode service to flag it for the admins.)

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How to tell if Windows partition is active?

    Check out using the WMI classes such as Win32_LogicalDisk or Win32_DiskPartition

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: How to tell if Windows partition is active?

    IOCTL_DISK_GET_PARTITION_INFO_EX looks like what you need.
    Best regards,
    Igor

  7. #7
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    894

    Re: How to tell if Windows partition is active?

    Arjay, thanks. I tried playing with those two WMI classes and although Win32_DiskPartition seems to have the 'BootPartition' property that looks like what I need, I couldn't find a way to connect to that class by a partition path. None of its properties come close to it.

    Igor, thanks for the info. I need to look into that ioctl function.

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How to tell if Windows partition is active?

    Quote Originally Posted by dc_2000 View Post
    Arjay, thanks. I tried playing with those two WMI classes and although Win32_DiskPartition seems to have the 'BootPartition' property that looks like what I need, I couldn't find a way to connect to that class by a partition path. None of its properties come close to it.

    Igor, thanks for the info. I need to look into that ioctl function.
    Use the WMI tools to view what you have on your system. One of the properties on it may identify the partition but not allow you to search by the property. If that is the case, then you can enumerate the disk partitions and select the match (based on the read-only property). Do a search on this forum for some WMI helper classes that I've written - it makes dealing with WMI fairly straightforward.

  9. #9
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: How to tell if Windows partition is active?

    what about..
    booting in windows (from an active partition)
    then from windows change the active partition so next reboot will be another OS
    yes, this can be done.

    Does that mean your diagnostic needs to fail because the currently active partition is not a windows one ?
    or do you need to know if the running windows was actually started from a partition that was active at the time of boot.
    How about if it was booted through a bootmenu that never made the Windows partition active ?
    How about a VM that just emulates a real disk where functions like asking about partitions may fail entirely because partitions don't exist.
    How about WINE on Linux ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured