帮助:MS虚拟磁盘服务访问本地计算机上的卷和光盘

帮助:MS虚拟磁盘服务访问本地计算机上的卷和光盘,第1张

概述帮助:MS虚拟磁盘服务访问本地计算机上的卷和光盘

这里是我的代码,我成功地初始化VDS服务,并获得包,但当我调用IVdsPack对象上的queryVolumes,我能够获得IEnumVdsObjects但无法通过IEnumVdsObject :: Next方法获得IUnkNown *数组,它会重新S_FALSE与IUnkown * = NulL。 所以这个IUnkNown *不能被用于IVdsVolume的queryInterface

以下是我的代码

HRESulT hResult; IVdsService* pService = NulL; IVdsServiceLoader *pLoader = NulL; //Launch the VDS Service hResult = CoInitialize(NulL); if( SUCCEEDED(hResult) ) { hResult = CoCreateInstance( CLSID_VdsLoader,NulL,CLSCTX_LOCAL_SERVER,IID_IVdsServiceLoader,(voID**) &pLoader ); //if succeeded load VDS on local machine if( SUCCEEDED(hResult) ) pLoader->LoadService(NulL,&pService); //Done with Loader Now release VDS Loader interface _SafeRelease(pLoader); if( SUCCEEDED(hResult) ) { hResult = pService->WaitForServiceReady(); if ( SUCCEEDED(hResult) ) { AfxMessageBox(L"VDS Service Loaded"); IEnumVdsObject* pEnumVdsObject = NulL; hResult = pService->queryProvIDers(VDS_query_SOFTWARE_PROVIDERS,&pEnumVdsObject); IUnkNown* ppObjUnk ; IVdsSwProvIDer* pVdsSwProvIDer = NulL; IVdsPack* pVdsPack = NulL; IVdsVolume* pVdsVolume = NulL; ulONG ulFetched = 0; hResult = E_INVALIDARG; while(!SUCCEEDED(hResult)) { hResult = pEnumVdsObject->Next(1,&ppObjUnk,&ulFetched); hResult = ppObjUnk->queryInterface(IID_IVdsSwProvIDer,(voID**)&pVdsSwProvIDer); if(!SUCCEEDED(hResult)) _SafeRelease(ppObjUnk); } _SafeRelease(pEnumVdsObject); _SafeRelease(ppObjUnk); hResult = pVdsSwProvIDer->queryPacks(&pEnumVdsObject); hResult = E_INVALIDARG; while(!SUCCEEDED(hResult)) { hResult = pEnumVdsObject->Next(1,&ulFetched); hResult = ppObjUnk->queryInterface(IID_IVdsPack,(voID**)&pVdsPack); if(!SUCCEEDED(hResult)) _SafeRelease(ppObjUnk); } _SafeRelease(pEnumVdsObject); _SafeRelease(ppObjUnk); hResult = pVdsPack->queryVolumes(&pEnumVdsObject); pEnumVdsObject->reset(); hResult = E_INVALIDARG; ulFetched = 0; BOol bDone = FALSE; while(!SUCCEEDED(hResult)) { hResult = pEnumVdsObject->Next(1,&ulFetched); //hResult = ppObjUnk->queryInterface(IID_IVdsVolume,(voID**)&pVdsVolume); if(!SUCCEEDED(hResult)) _SafeRelease(ppObjUnk); } _SafeRelease(pEnumVdsObject); _SafeRelease(ppObjUnk); _SafeRelease(pVdsPack); _SafeRelease(pVdsSwProvIDer); // hResult = pVdsVolume->AddAccesspath(TEXT("G:\")); if(SUCCEEDED(hResult)) AfxMessageBox(L"Add Access Path Successfully"); else AfxMessageBox(L"Unable to Add access path"); //UUID of IVdsVolumeMF {EE2D5DED-6236-4169-931D-B9778CE03DC6} static const GUID GUID_IVdsVolumeMF = {0xEE2D5DED,0x6236,4169,{0x93,0x1D,0xB9,0x77,0x8C,0xE0,0x3D,0XC6} }; hResult = pService->Getobject(GUID_IVdsVolumeMF,VDS_OT_VolUME,&ppObjUnk); if(hResult == VDS_E_OBJECT_NOT_FOUND) AfxMessageBox(L"Object Not found"); if(hResult == VDS_E_INITIAliZED_Failed) AfxMessageBox(L"Initialization Failed"); // pVdsVolume = reinterpret_cast<IVdsVolumeMF*>(ppObjUnk); if(SUCCEEDED(hResult)) { // hResult = pVdsVolume->AddAccesspath(TEXT("G:\")); if(SUCCEEDED(hResult)) { IVdsAsync* ppVdsSync; AfxMessageBox(L"Formatting is about to Start......"); // hResult = pVdsVolume->Format(VDS_FST_UDF,TEXT("UDF_FORMAT_TEST"),2048,TRUE,FALSE,&ppVdsSync); if(SUCCEEDED(hResult)) AfxMessageBox(L"Formatting Started......."); else AfxMessageBox(L"Formatting Failed"); } else AfxMessageBox(L"Unable to Add Access Path"); } _SafeRelease(pVdsVolume); } else { AfxMessageBox(L"VDS Service Cannot be Loaded"); } } } _SafeRelease(pService);

Getopenfilename()干扰SFML

VC ++预处理器符号的描述

fseeko,fseeko64; ftello,ftello64 Visual C等价物

CreateProcess()似乎不受lpCurrentDirectory的影响

可以安全地使用用户定义的types吗?

Win32:获取其他应用程序closures/退出的消息通知

在linux中,是否存在类似于_clearfp()和_statusfp()的函数?

你如何在windows中像静态库一样释放代码

在Win 7和8.1中deBUGgingshell扩展

获取由windows 8及以上版本的NetWkstaUserEnum API返回的给定Microsoft帐户的本地login名

你需要在你的while循环里面枚举你的IVdsSwProvIDers。

我修改你的代码是为了我自己的目的。 你必须小心,因为我把它扔在一起进行测试,因此不关心内存泄漏和释放COM对象。 我也有很多调试打印:

#include "stdafx.h" #include "initguID.h" #include <vds.h> #include <stdio.h> #pragma comment( lib,"ole32.lib" ) #pragma comment( lib,"rpcrt4.lib" ) #define _SafeRelease(x) {if (NulL != x) { x->Release(); x = NulL; } } voID Enumeratedisks(IVdsPack* pPack) { HRESulT hResult; ulONG ulFetched = 0; IUnkNown* ppObjUnk ; IEnumVdsObject* pEnumVdsObject = NulL; IVdsdisk* pVdsdisk = NulL; IVdsdisk2* pVdsdisk2 = NulL; IVdsAdvanceddisk* pVdsAdvanceddisk = NulL; if (pPack == 0) return; hResult = pPack->querydisks(&pEnumVdsObject); if (pEnumVdsObject == 0) return; while( true) { if (!pEnumVdsObject) break; hResult = pEnumVdsObject->Next(1,&ulFetched); if (ulFetched == 0) break; hResult = ppObjUnk->queryInterface(IID_IVdsdisk,(voID**)&pVdsdisk); VDS_disK_PROP diskProp; pVdsdisk->GetPropertIEs(&diskProp); printf("----------------------------------------n"); wprintf(L"disk: %dn",diskProp.status); wprintf(L"disk: %sn",diskProp.pwszAdaptorname); wprintf(L"disk: %sn",diskProp.pwszDevicePath); wprintf(L"disk: %sn",diskProp.pwszFrIEndlyname); wprintf(L"disk: %sn",diskProp.pwszname); wprintf(L"disk: %dn",diskProp.DWDeviceType); wprintf(L"disk: %dn",diskProp.DWMediaType); wprintf(L"disk: %dn",diskProp.DWSignature); wprintf(L"disk: %dn",diskProp.PartitionStyle); wprintf(L"disk: %dn",diskProp.ReserveMode); wprintf(L"disk: %dn",diskProp.ulFlags); VDS_PARTITION_PROP * pPropArray = NulL; LONG pNumberOfPartitions = 0; hResult = ppObjUnk->queryInterface(IID_IVdsAdvanceddisk,(voID**)&pVdsAdvanceddisk); pVdsAdvanceddisk->queryPartitions(&pPropArray,&pNumberOfPartitions); VDS_PARTITION_PROP * tmp = pPropArray; for (int i = 0; i < pNumberOfPartitions; ++i) { printf("Number: %dn",tmp->ulPartitionNumber); printf("Style : %dn",tmp->PartitionStyle); printf("Flags : %dn",tmp->ulFlags); printf("Offset: %ulln",tmp->ullOffset); printf("Size: %ulln",tmp->ullSize); printf("MBR type: %dn",tmp->Mbr.partitionType); printf("MBR type: %dn",tmp->Mbr.bootIndicator); printf("MBR type: %dn",tmp->Mbr.recognizedPartition); printf("MBR type: %dn",tmp->Mbr.hIDdenSectors); ++tmp; } CoTaskMemFree(pPropArray); } } voID EnumerateVolumes(IVdsPack* pPack) { HRESulT hResult; ulONG ulFetched = 0; IUnkNown* ppObjUnk ; IEnumVdsObject* pEnumVdsObject = NulL; IVdsVolume* pVdsVolume = NulL; if (pPack == 0) return; hResult = pPack->queryVolumes(&pEnumVdsObject); if (pEnumVdsObject == 0) return; while( true) { hResult = pEnumVdsObject->Next(1,&ulFetched); if (ulFetched == 0) break; hResult = ppObjUnk->queryInterface(IID_IVdsVolume,(voID**)&pVdsVolume); VDS_VolUME_PROP volProp; pVdsVolume->GetPropertIEs(&volProp); printf("Vol name : %sn",volProp.pwszname); printf("Vol health: %dn",volProp.health); } } voID EnumeratePacks(IVdsSwProvIDer* pProvIDer) { HRESulT hResult; ulONG ulFetched = 0; IUnkNown* ppObjUnk ; IEnumVdsObject* pEnumVdsObject = NulL; IVdsPack* pVdsPack = NulL; if (pProvIDer == 0) return; hResult = pProvIDer->queryPacks(&pEnumVdsObject); if (pEnumVdsObject == 0) return; while( true) { hResult = pEnumVdsObject->Next(1,&ulFetched); if (ulFetched == 0) break; hResult = ppObjUnk->queryInterface(IID_IVdsPack,(voID**)&pVdsPack); VDS_PACK_PROP packProp; pVdsPack->GetPropertIEs(&packProp); if (packProp.status == VDS_PS_ONliNE) { printf("Pack name : %sn",packProp.pwszname); printf("Pack status: %dn",packProp.status); printf("Pack flags : %dn",packProp.ulFlags); Enumeratedisks(pVdsPack); EnumerateVolumes(pVdsPack); } } } voID EnumerateSoftwareProvIDers(IVdsService* pService) { HRESulT hResult; ulONG ulFetched = 0; IUnkNown* ppObjUnk ; IEnumVdsObject* pEnumVdsObject = NulL; IVdsSwProvIDer* pVdsSwProvIDer = NulL; hResult = pService->queryProvIDers(VDS_query_SOFTWARE_PROVIDERS,&pEnumVdsObject); while( true) { hResult = pEnumVdsObject->Next(1,&ulFetched); if (ulFetched == 0) break; hResult = ppObjUnk->queryInterface(IID_IVdsSwProvIDer,(voID**)&pVdsSwProvIDer); EnumeratePacks(pVdsSwProvIDer); } } int __cdecl main(voID) { ////////////////////////////////////////////////////////////////// HRESulT hResult; IVdsService* pService = NulL; IVdsServiceLoader *pLoader = NulL; //Launch the VDS Service hResult = CoInitializeEx(NulL,COINIT_MulTITHREADED); // Initialize COM security CoInitializeSecurity( NulL,// Allow *all* VSS writers to communicate back! -1,// Default COM authentication service NulL,// Default COM authorization service NulL,// reserved parameter RPC_C_AUTHN_LEVEL_PKT_PRIVACY,// Strongest COM authentication level RPC_C_IMP_LEVEL_IMPERSONATE,// Minimal impersonation abilitIEs NulL,// Default COM authentication settings EOAC_NONE,// No special options NulL // Reserved parameter ); if( SUCCEEDED(hResult) ) { hResult = CoCreateInstance( CLSID_VdsLoader,&pService); //Done with Loader Now release VDS Loader interface _SafeRelease(pLoader); if( SUCCEEDED(hResult) ) { hResult = pService->WaitForServiceReady(); if ( SUCCEEDED(hResult) ) { EnumerateSoftwareProvIDers(pService); return 0; } } } return -1; }

总结

以上是内存溢出为你收集整理的帮助:MS虚拟磁盘服务访问本地计算机上的卷和光盘全部内容,希望文章能够帮你解决帮助:MS虚拟磁盘服务访问本地计算机上的卷和光盘所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1158516.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存