| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 635 人关注过本帖
标题:用c语言如何查看系统盘状态
只看楼主 加入收藏
aufish
Rank: 2
等 级:论坛游民
威 望:1
帖 子:59
专家分:94
注 册:2010-4-22
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:4 
用c语言如何查看系统盘状态
用C语言如何查看系统盘状态。
如输入命 chkdsk后
输出系统盘(c)的存储状态等
搜索更多相关主题的帖子: c语言 系统 状态 
2010-12-15 20:21
cnfarer
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:179
帖 子:3330
专家分:21157
注 册:2010-1-19
收藏
得分:0 
使用相关API调用

★★★★★为人民服务★★★★★
2010-12-15 20:57
aufish
Rank: 2
等 级:论坛游民
威 望:1
帖 子:59
专家分:94
注 册:2010-4-22
收藏
得分:0 
回复 2楼 cnfarer
能具体点吗?
2010-12-15 21:50
cnfarer
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:179
帖 子:3330
专家分:21157
注 册:2010-1-19
收藏
得分:20 
主要API函数原型说明如下:

  1.获取系统中逻辑驱动器的数量

The GetLogicalDrives function retrieves a bitmask representing the currently available disk drives.

DWORD GetLogicalDrives(void);
 

  2.获取所有驱动器字符串信息

The GetLogicalDriveStrings function fills a buffer with strings that specify valid drives in the system.

DWORD GetLogicalDriveStrings(
  DWORD nBufferLength,
  LPTSTR lpBuffer
);

  3.获取驱动器类型

The GetDriveType function determines whether a disk drive is a removable, fixed, CD-ROM, RAM disk, or network drive.

UINT GetDriveType(
  LPCTSTR lpRootPathName
);

  4. 获取驱动器磁盘的空间状态,函数返回的是个BOOL类型数据

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
);


★★★★★为人民服务★★★★★
2010-12-16 07:53
aufish
Rank: 2
等 级:论坛游民
威 望:1
帖 子:59
专家分:94
注 册:2010-4-22
收藏
得分:0 
我完成拉!
#include <windows.h>
#include <stdio.h>

typedef BOOL (WINAPI *PGETDISKFREESPACEEX)(LPCSTR,
                                           PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);

BOOL MyGetDiskFreeSpaceEx(LPCSTR pszDrive)
{
    PGETDISKFREESPACEEX pGetDiskFreeSpaceEx;
    __int64 i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes;
   
    DWORD dwSectPerClust,
        dwBytesPerSect,
        dwFreeClusters,
        dwTotalClusters;
   
    BOOL fResult;
   
    pGetDiskFreeSpaceEx = (PGETDISKFREESPACEEX) GetProcAddress(
        GetModuleHandle("kernel32.dll"),
        "GetDiskFreeSpaceExA");
   
    if (pGetDiskFreeSpaceEx)
    {
        fResult = pGetDiskFreeSpaceEx (pszDrive,
            (PULARGE_INTEGER)&i64FreeBytesToCaller,
            (PULARGE_INTEGER)&i64TotalBytes,
            (PULARGE_INTEGER)&i64FreeBytes);
        
        // Process GetDiskFreeSpaceEx results.
        if(fResult)
        {
            printf("\n已用空间: %10.2fGB\n", (float)i64TotalBytes/(1024*1024*1024)-(float)i64FreeBytesToCaller/(1024*1024*1024));
            printf("可用空间: %10.2fGB\n", (float)i64FreeBytes/(1024*1024*1024));
            printf("总空间:   %10.2fGB\n", (float)i64TotalBytes/(1024*1024*1024));
        }
        return fResult;
    }
   
    else
    {
        fResult = GetDiskFreeSpaceA (pszDrive,
            &dwSectPerClust,
            &dwBytesPerSect,
            &dwFreeClusters,
            &dwTotalClusters);
        
        // Process GetDiskFreeSpace results.
        if(fResult)
        {
            printf("Total free bytes = I64d\n",
                dwFreeClusters*dwSectPerClust*dwBytesPerSect);
        
        }
        return fResult;
    }
}
int main(int argc, char *argv[])
{
    MyGetDiskFreeSpaceEx ("c:");
}
2010-12-16 18:22
快速回复:用c语言如何查看系统盘状态
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021040 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved