C y las api de windows

Hola estudio ingenieria en informatica debo hacer una tarea pero no se muy bien como. Debo usar C para generar un programa en windows 2000 que se ejecute en segundo plano, se inicie como servicio y cada 10 minutos verifique la cantidad de disco duro disponible, si esta es mayor al 90% enviar un mensaje de alarma.
Se que hay una api de windows que entrega el espacio disponible pero no se cual es ni como se ocupa.
podrias ayudarme?

1 respuesta

Respuesta
1
La funcion GetDiskFreeSpaceEx es la indicada para este caso ya que te retorna el espacio libre y el espacio utilizado ademas de que la funcion original GetDiskFreeSpace no funcionaba con discos que tenias mas de 2 GB. Te anexo informacion que consegui en el MSDN de Microsoft
The GetDiskFreeSpaceEx function retrieves information about the amount of space available on a disk volume: the total amount of space, the total amount of free space, and the total amount of free space available to the user associated with the calling thread.
BOOL GetDiskFreeSpaceEx(
LPCTSTR lpDirectoryName,
PULARGE_INTEGER lpFreeBytesAvailable,
PULARGE_INTEGER lpTotalNumberOfBytes,
PULARGE_INTEGER lpTotalNumberOfFreeBytes
);
Parameters
lpDirectoryName
[in] Pointer to a null-terminated string that specifies a directory on the disk of interest. If this parameter is NULL, the function uses the root of the current disk. If this parameter is a UNC name, it must include a trailing backslash (for example, \\MyServer\MyShare\).
Note that this parameter does not have to specify the root directory on a disk. The function accepts any directory on the disk.
lpFreeBytesAvailable
[out] Pointer to a variable that receives the total number of free bytes on the disk that are available to the user associated with the calling thread. This parameter can be NULL.
If per-user quotas are in use, this value may be less than the total number of free bytes on the disk.
lpTotalNumberOfBytes
[out] Pointer to a variable that receives the total number of bytes on the disk that are available to the user associated with the calling thread. This parameter can be NULL.
If per-user quotas are in use, this value may be less than the total number of bytes on the disk.
lpTotalNumberOfFreeBytes
[out] Pointer to a variable that receives the total number of free bytes on the disk. This parameter can be NULL.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
Note that the values obtained by this function are of type ULARGE_INTEGER. Be careful not to truncate these values to 32 bits.
Windows 95 OSR2 and later: The GetDiskFreeSpaceEx function is available beginning with Windows 95 OEM Service Release 2 (OSR2). To determine whether GetDiskFreeSpaceEx is available, call GetModuleHandle to get the handle to Kernel32.dll. Then you can call GetProcAddress.
The following code fragment shows one way to do this:
pGetDiskFreeSpaceEx = GetProcAddress( GetModuleHandle("kernel32.dll"),
"GetDiskFreeSpaceExA");
if (pGetDiskFreeSpaceEx)
{
fResult = pGetDiskFreeSpaceEx (pszDrive,
(PULARGE_INTEGER)&i64FreeBytesToCaller,
(PULARGE_INTEGER)&i64TotalBytes,
(PULARGE_INTEGER)&i64FreeBytes);
// Process GetDiskFreeSpaceEx results.
}
else
{
fResult = GetDiskFreeSpace (pszDrive,
&dwSectPerClust,
&dwBytesPerSect,
&dwFreeClusters,
&dwTotalClusters)
// Process GetDiskFreeSpace results.
}
It is not necessary to call LoadLibrary on Kernel32.dll because it is already loaded into every process address space.
Windows NT Server 3.51 and earlier, Windows 95: Include an additional header file called NewAPIs. H to make GetDiskFreeSpaceEx available on these operating systems. The function is not implemented natively, but by a wrapper that utilizes other native functions on these systems. See the header file for details of the use of preprocessor directives that make the function available. If you do not have this header file, it can be obtained by downloading the most recent Windows SDK from the SDK Update Site.
Windows Me/98/95 OSR2: GetDiskFreeSpaceExW is supported by the Microsoft Layer for Unicode. To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.
Requirements
Client: Included in Windows XP, Windows 2000 Professional, Windows NT Workstation 4.0, Windows Me, Windows 98, and Windows 95 OSR2 and later.
Server: Included in Windows Server 2003, Windows 2000 Server, and Windows NT Server 4.0.
Unicode: Implemented as Unicode and ANSI versions. Note that Unicode support on Windows Me/98/95 requires Microsoft Layer for Unicode.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32. Lib.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas