0
我有以下代碼來查找UNC路徑上的可用磁盤空間。當我以調試模式運行時,我得到了正確的值,但是當我在發佈模式下運行時,GetFreeDiskSpaceEx函數出現1326登錄失敗。我甚至使用過上面調用GetFreeDiskSpaceEx的NetUseAdd。有人可以告訴如何從UNC獲取磁盤空間嗎?以下是我正在使用的功能。UNC路徑上的GetFreeDiskSpaceEx
void FreeSpaceOnPath(LPCWSTR Path, unsigned __int64* freeBytesAvailable, unsigned __int64* totalNumberOfBytes)
{
// set the structure (use_info_2)
USE_INFO_2 u;
// set netuseadd and error checking variables
DWORD rc, error=0;
memset(&u, '\0', sizeof u);
//fill in the USER_INFO_2 for connection infor
u.ui2_local = NULL;
u.ui2_remote = (LPWSTR) L"\\\\10.0.0.113\\e";;
u.ui2_password = (LPWSTR) L"password#123"; //specify no password
u.ui2_username = (LPWSTR) L"10.0.0.113\\user"; // specify no username
u.ui2_asg_type = USE_WILDCARD;
rc = NetUseAdd(NULL, 1, (byte *) &u, &error);
DWORD lasterror = GetLastError();
printf("GetLastError:%d\n", lasterror);
ULARGE_INTEGER freeBytesAvailable2, totalNumberOfFreeBytes, totalNumberOfBytes2;
BOOL ok = GetDiskFreeSpaceEx(Path, &freeBytesAvailable2, &totalNumberOfBytes2, &totalNumberOfFreeBytes);
DWORD err = GetLastError();
printf("Value returned for GetDiskFreeSpaceEx: %d GetLastError:%d\n", ok, err);
wprintf(L"Dir: %s\n", dir);
printf("Value returned for GetDiskFreeSpaceEx: %d\n", ok);
if (ok)
{
*freeBytesAvailable = freeBytesAvailable2.QuadPart;
*totalNumberOfBytes = totalNumberOfBytes2.QuadPart;
}