2014-11-24 179 views

回答

1

檢查此鏈接(http://msdn.microsoft.com/en-us/library/windows/desktop/aa365451(v=vs.85).aspx

PARTITION_INFORMATION有BootIndicator。但不能保證運行的窗口是由該分區啓動的。

編輯這是在Windows7上測試的一個示例函數。我認爲'激活'分區不是你的目標。 '激活'具有可引導的USB設備的含義。我不喜歡WMI但它可以幫助你的目標(http://msdn.microsoft.com/en-us/library/windows/desktop/bb986746(v=vs.85).aspx

BOOL 
__stdcall 
TP_IsPartitionActivated(
__in LPCWSTR pPartition, 
__out PBOOL pbIsActivated 
) 
{ 
    HANDLE hDevice = INVALID_HANDLE_VALUE; 
    PARTITION_INFORMATION_EX szPartitionInformation; 
    DWORD cbReturned = 0x00; 

    if (pPartition == NULL || pbIsActivated == NULL) { return FALSE; } 

    __try 
    { 
     hDevice = CreateFileW(pPartition, 0x00, 0x00, NULL, OPEN_EXISTING, 0x00, NULL); 
     if (hDevice == INVALID_HANDLE_VALUE) { return FALSE; } 

     RtlZeroMemory(&szPartitionInformation, sizeof(szPartitionInformation)); 
     if (FALSE != DeviceIoControl(hDevice, IOCTL_DISK_GET_PARTITION_INFO_EX, NULL, 0x00, (LPVOID)&szPartitionInformation, sizeof(PARTITION_INFORMATION_EX), &cbReturned, NULL)) 
     { 
      if (PARTITION_STYLE_MBR == szPartitionInformation.PartitionStyle) 
      { 
       *pbIsActivated = szPartitionInformation.Mbr.BootIndicator; 
      } 
      else 
      { 
      } 

      return TRUE; 
     } 
     else 
     { 
      cbReturned = GetLastError(); 
      wprintf(L"%08X(%d)\n", cbReturned, cbReturned); 
     } 
    } 
    __finally 
    { 
     if (hDevice != INVALID_HANDLE_VALUE) { CloseHandle(hDevice); } 
    } 

    return FALSE; 
} 

呼叫像

WCHAR szPartition[] = L"\\\\.\\C:"; 
BOOL bIsActivated = FALSE; 

if (FALSE != TP_IsPartitionActivated(szPartition, &bIsActivated)) 
{ 
    wprintf(L"%s \n", bIsActivated == FALSE ? L"not activated" : L"activated"); 
} 
else 
{ 
    wprintf(L"function fail\n"); 
} 
+0

如果你不介意我問,爲什麼我會想,如果'使用它,然後它不保證'? – c00000fd 2014-11-24 04:33:25

+0

@ c00000fd:這回答您的問題,即它顯示分區是否處於活動狀態。當前正在通過此分區啓動的Windows實例是否是另一個問題。 – 2014-11-24 04:44:04

+0

@HarryJohnston:好的。我懂了。這可能是他措辭的方式。 – c00000fd 2014-11-24 05:00:21

相關問題