Click here to Skip to main content
15,888,111 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: I want to use the mini filter driver IRP_MJ_CREATE only for opening existing files(exe files). Pin
Stefan_Lang19-Aug-20 21:48
Stefan_Lang19-Aug-20 21:48 
QuestionHow to get allocated blocks for VHDx? queryChangesVirtualDisk gives ACCESS DENIED. Pin
cazorla1914-Aug-20 3:30
cazorla1914-Aug-20 3:30 
AnswerRe: How to get allocated blocks for VHDx? queryChangesVirtualDisk gives ACCESS DENIED. Pin
Gerry Schmitz14-Aug-20 5:04
mveGerry Schmitz14-Aug-20 5:04 
GeneralRe: How to get allocated blocks for VHDx? queryChangesVirtualDisk gives ACCESS DENIED. Pin
cazorla1918-Aug-20 0:57
cazorla1918-Aug-20 0:57 
GeneralRe: How to get allocated blocks for VHDx? queryChangesVirtualDisk gives ACCESS DENIED. Pin
Gerry Schmitz18-Aug-20 5:34
mveGerry Schmitz18-Aug-20 5:34 
AnswerRe: How to get allocated blocks for VHDx? queryChangesVirtualDisk gives ACCESS DENIED. Pin
Randor 14-Aug-20 8:54
professional Randor 14-Aug-20 8:54 
GeneralRe: How to get allocated blocks for VHDx? queryChangesVirtualDisk gives ACCESS DENIED. Pin
cazorla1918-Aug-20 0:55
cazorla1918-Aug-20 0:55 
GeneralRe: How to get allocated blocks for VHDx? queryChangesVirtualDisk gives ACCESS DENIED. Pin
Randor 19-Aug-20 19:04
professional Randor 19-Aug-20 19:04 
Hi Hari,

Kinda looks like you are breaking the rules of nearly everything in the Remarks section for the OpenVirtualDisk function for a permanently attached virtual disk.

This is working for me, code is ugly, there is no error handling... it's just a code sample:

C++
#include <iostream>
#include <windows.h>
#include <virtdisk.h>
#include <tchar.h>
#include <comdef.h>
#include <atlcomcli.h>
#include <wbemidl.h>

#pragma comment(lib, "wbemuuid.lib")
#pragma comment(lib, "virtdisk.lib")

const GUID VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT = {0xec984aec, 0xa0f9, 0x47e9, 0x90, 0x1f, 0x71, 0x41, 0x5a, 0x66, 0x34, 0x5b};
const GUID VIRTUAL_STORAGE_TYPE_VENDOR_UNKNOWN = { 0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

int main()
{
	HANDLE vhdHandle = NULL;
	VIRTUAL_STORAGE_TYPE storageType = {};
	ULONG  status = 0L;

	//storageType.DeviceId = VIRTUAL_STORAGE_TYPE_DEVICE_VHDX;
	//storageType.VendorId = VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT;
	storageType.DeviceId = VIRTUAL_STORAGE_TYPE_DEVICE_UNKNOWN;
	storageType.VendorId = VIRTUAL_STORAGE_TYPE_VENDOR_UNKNOWN;

	PCWSTR virtualDiskPath = L"D:\\VirtualMachines\\x64_Windows8.1\\x64_Windows8.1\\Virtual Hard Disks\\x64_Windows8.1.vhdx";

	OPEN_VIRTUAL_DISK_PARAMETERS* pOpenParameter = NULL;

	status = OpenVirtualDisk(&storageType, virtualDiskPath,VIRTUAL_DISK_ACCESS_ATTACH_RW | VIRTUAL_DISK_ACCESS_GET_INFO | VIRTUAL_DISK_ACCESS_DETACH,OPEN_VIRTUAL_DISK_FLAG_NONE, pOpenParameter, &vhdHandle);

	if (ERROR_SUCCESS == status)
	{
		DWORD sizeUsed = GET_VIRTUAL_DISK_INFO_SIZE;
		WCHAR changeTrackingInfo[sizeof(GET_VIRTUAL_DISK_INFO) + sizeof(GUID)];
		::ZeroMemory(changeTrackingInfo, sizeof(changeTrackingInfo));
		PGET_VIRTUAL_DISK_INFO virtualDiskInfo = (GET_VIRTUAL_DISK_INFO*)changeTrackingInfo;
		virtualDiskInfo->Version = (GET_VIRTUAL_DISK_INFO_VERSION)GET_VIRTUAL_DISK_INFO_CHANGE_TRACKING_STATE;
		ULONG virtualDiskInfoSize = sizeof(changeTrackingInfo);

		status = GetVirtualDiskInformation(vhdHandle, &virtualDiskInfoSize, virtualDiskInfo, &sizeUsed);

		if (ERROR_SUCCESS == status)
		{
			ULONG64 virtualDiskSize = virtualDiskInfo->Size.VirtualSize;

			printf("Disk Infomation:\n");
			GUID virtualDiskGuid = virtualDiskInfo->Identifier;
			wchar_t szGUID[64] = { 0 };
			StringFromGUID2(virtualDiskGuid, szGUID, 64);
			wprintf(L"ChangeTrackingState.Enabled:%d\n", virtualDiskInfo->ChangeTrackingState.Enabled);
			wprintf(L"ChangeTrackingState.MostRecentId:%s\n", virtualDiskInfo->ChangeTrackingState.MostRecentId);
			wprintf(L"Identifier\t= %s\n", szGUID);
			wprintf(L"Physical Size\t= %I64u\n", virtualDiskInfo->Size.PhysicalSize);
			wprintf(L"Virtual Size\t= %I64u\n", virtualDiskInfo->Size.VirtualSize);
			wprintf(L"Sector Size\t= %u\n", virtualDiskInfo->Size.SectorSize);
			wprintf(L"Block Size\t= %u\n", virtualDiskInfo->Size.BlockSize);
		}
	}
	return 0;
}


Best Wishes,
-Rubeus Hagrid
QuestionRe: How to get allocated blocks for VHDx? queryChangesVirtualDisk gives ACCESS DENIED. Pin
cazorla1919-Aug-20 20:26
cazorla1919-Aug-20 20:26 
AnswerRe: How to get allocated blocks for VHDx? queryChangesVirtualDisk gives ACCESS DENIED. Pin
Randor 19-Aug-20 20:57
professional Randor 19-Aug-20 20:57 
GeneralRe: How to get allocated blocks for VHDx? queryChangesVirtualDisk gives ACCESS DENIED. Pin
cazorla1919-Aug-20 21:29
cazorla1919-Aug-20 21:29 
GeneralRe: How to get allocated blocks for VHDx? queryChangesVirtualDisk gives ACCESS DENIED. Pin
Randor 19-Aug-20 21:47
professional Randor 19-Aug-20 21:47 
QuestionMicrosoft Media Foundation AAC Decoder using C++ Pin
sabid12-Aug-20 18:32
sabid12-Aug-20 18:32 
AnswerRe: Microsoft Media Foundation AAC Decoder using C++ Pin
Richard MacCutchan12-Aug-20 21:04
mveRichard MacCutchan12-Aug-20 21:04 
AnswerRe: Microsoft Media Foundation AAC Decoder using C++ Pin
11917640 Member 2-Sep-20 1:06
11917640 Member 2-Sep-20 1:06 
QuestionIs there an entry point for CppUnitTestFramework unit tests ? Pin
Maximilien11-Aug-20 10:01
Maximilien11-Aug-20 10:01 
AnswerRe: Is there an entry point for CppUnitTestFramework unit tests ? Pin
Richard MacCutchan11-Aug-20 22:23
mveRichard MacCutchan11-Aug-20 22:23 
GeneralRe: Is there an entry point for CppUnitTestFramework unit tests ? Pin
Maximilien12-Aug-20 7:31
Maximilien12-Aug-20 7:31 
Questioncomputer science Pin
Member 1491094810-Aug-20 0:26
Member 1491094810-Aug-20 0:26 
AnswerRe: computer science Pin
Daniel Pfeffer10-Aug-20 0:45
professionalDaniel Pfeffer10-Aug-20 0:45 
AnswerRe: computer science Pin
Richard MacCutchan10-Aug-20 3:24
mveRichard MacCutchan10-Aug-20 3:24 
Questionsorce code grid line Pin
SADEGH20771-Aug-20 7:44
SADEGH20771-Aug-20 7:44 
AnswerRe: sorce code grid line Pin
Victor Nijegorodov1-Aug-20 8:15
Victor Nijegorodov1-Aug-20 8:15 
GeneralRe: sorce code grid line Pin
SADEGH20771-Aug-20 8:24
SADEGH20771-Aug-20 8:24 
GeneralRe: sorce code grid line Pin
SADEGH20771-Aug-20 8:25
SADEGH20771-Aug-20 8:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.