获取远程应用服务器文件夹配额信息

#include <windows.h>
#include <stdio.h>
#include <comutil.h>
#include <FsrmQuota.h>  // Quota objects
#include <FsrmTlb.h>    // Contains CLSIDs.

#pragma comment(lib, "comsupp.lib")
void wmain(void)
{
	HRESULT hr = S_OK;
	IFsrmQuotaManager* pFsrmQuotaManager = NULL;
	IFsrmQuota* pQuota = NULL;
	VARIANT var;
	DATE date;
	SYSTEMTIME st;

	hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
	if (FAILED(hr))
	{
		wprintf(L"CoInitializeEx() failed, 0x%x.\n", hr);
		return;
	}

	hr = CoCreateInstance(CLSID_FsrmQuotaManager, 
		NULL,
		CLSCTX_LOCAL_SERVER,
		__uuidof(IFsrmQuotaManager),
		reinterpret_cast<void**> (&pFsrmQuotaManager));

	if (FAILED(hr))
	{
		wprintf(L"CoCreateInstance(FsrmQuotaManager) failed, 0x%x.\n", hr);
		if (E_ACCESSDENIED == hr)
			wprintf(L"Access denied. You must run the client with an elevated token.\n");

		goto cleanup;
	}

	// Get the quota that applies to the specified directory.
	hr = pFsrmQuotaManager->GetQuota(_bstr_t(L"c:\\5m"), &pQuota);
	if (FAILED(hr))
	{
		wprintf(L"pFsrmQuotaManager->GetQuota failed, 0x%x.\n", hr);
		goto cleanup;
	}

	VariantInit(&var);

	// Get the quota limit.
	hr = pQuota->get_QuotaLimit(&var);
	if (FAILED(hr))
	{
		wprintf(L"pQuota->get_QuotaLimit failed, 0x%x.\n", hr);
		goto cleanup;
	}

	wprintf(L"Limit: %I64u\n", var.ullVal);
	VariantClear(&var);

	// Get the amount of disk space usage charged to this quota.
	hr = pQuota->get_QuotaUsed(&var);
	if (FAILED(hr))
	{
		wprintf(L"pQuota->get_QuotaUsed failed, 0x%x.\n", hr);
		goto cleanup;
	}

	wprintf(L"Used: %I64u\n", var.ullVal);
	VariantClear(&var);

	// Get the highest amount of disk space usage charged to this quota.
	hr = pQuota->get_QuotaPeakUsage(&var);
	if (FAILED(hr))
	{
		wprintf(L"pQuota->get_QuotaPeakUsage failed, 0x%x.\n", hr);
		goto cleanup;
	}

	wprintf(L"PeakUsage: %I64u\n", var.ullVal);

	// Get the date and time when the peak usage occurred.
	hr = pQuota->get_QuotaPeakUsageTime(&date);
	if (FAILED(hr))
	{
		wprintf(L"pQuota->get_QuotaPeakUsageTime failed, 0x%x.\n", hr);
		goto cleanup;
	}

	if (VariantTimeToSystemTime(date, &st))
		wprintf(L"Peak usage occurred on %d\\%d\\%d at %d:%d", st.wMonth, st.wDay, st.wYear, st.wHour, st.wMinute);

cleanup:

	if (pFsrmQuotaManager)
		pFsrmQuotaManager->Release();

	if (pQuota)
		pQuota->Release();

	VariantClear(&var);

	CoUninitialize();
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值