Sign in with
Sign up | Sign in
Your question

GetDiskFreeSpaceEx called from a service doesn't work

Tags:
Last response: in Windows 2000/NT
Share
April 7, 2004 1:09:19 AM

Archived from groups: microsoft.public.win2000.file_system (More info?)

Hi,

I'm not sure if I'm supposed to ask developer questions here - but I didn't
have any luck in other newsgroups. That said:

I'm using the GetDiskFreeSpaceEx() API call and I'm getting really strange
results when I call this API from a service on one machine, a Windows XP
(fully patched) machine. The code looks like this:

ULARGE_INTEGER uiNotUsed, uiTotalNumberBytes, uiTotalNumberFreeBytes;

if (GetDiskFreeSpaceEx(cDrive, &uiNotUsed, &uiTotalNumberBytes,
&uiTotalNumberFreeBytes))
{
__int64 iFree64 = uiTotalNumberFreeBytes.QuadPart / (1024 * 1024);
__int64 iTotal64 = uiTotalNumberBytes.QuadPart / (1024 * 1024);

int iFree = iFree64;
int iTotal = iTotal64;
}

I also tried loading the address of the function at run-time with

typdef ....
GETDISKFREESPACEEX pGetDiskFreeSpaceEx = (GETDISKFREESPACEEX)
GetProcAddress( GetModuleHandle("kernel32.dll"), "GetDiskFreeSpaceExA");

but it yields the same exact results - no difference there. Again, it will
work fine if I run this from a test command-line app, just not when I call
this from the service I am working on.

So I'm basically trying to store the number of megabytes in an integer
variable. This works on all Win2k (4) and Windows Server 2003 (2) machines
and works on two XP machines. But there is one laptop (that has no other
problems) where I will always get these values for both the total and free
space:

1407374883553280 (which is 0x5000000000000)

The strange this is that the same code will work just fine if I create a
test app and launch it from the command line, I will get the correct values.
But not when I run this code from the service. It doesn't bother me too much
that it's not working on that one machine, but I'm worried that many more
machines in a production enviornment might be affected.

Can anybody explain to me what the **** is going on here? The laptop has one
harddisk (60Gb) with two logical drives (35.6Gb/2.33Gb free & 18.6Gb/6.42Gb
free) but I doubt that the HD has anything to do with it.

I'm at a point where I can't use the app on this computer - and I'm worried
that I'm going to find more like that ... I couldn't find any problems in
technet,kb etc. so far. If I'm doing something wrong then I'd love to know
what I am doing wrong .... Even a printf("%i64d",
uiTotalNumberFreeBytes.QuadPart) shows the odd values ...

I read about somebody else having a similar problem with a service written
in VB - only that it was Windows Server 2003 and not XP. Sounds similar
enough to me though - in that case the values returned were way too high
also. I wonder if there is an issue not widely known. Will I have to contact
MS Support for this and if so where do I go? Do they even provide any
support for developers for stuff like that?


Thanks a lot for ANY thoughts ...
!