zoukankan      html  css  js  c++  java
  • delphi读取磁盘信息

    delphi之磁盘篇

      1.读硬盘序列号

    function GetDiskSerial(DiskChar: Char): string;

    var

    SerialNum : pdword;
    a, b : dword;
    Buffer : array [0..255] of char;
    begin
    result := "";
    if GetVolumeInformation(PChar(diskchar+":\"), Buffer, SizeOf(Buffer), SerialNum,
    a, b, nil, 0) then
     Result := IntToStr(SerialNum^);

    end;

      2.检查磁盘是否就绪

    Function DiskReady(Root: string) : Boolean;

    var

    Oem : CARDINAL ;
    Dw1,Dw2 : DWORD ;

    begin

    Oem := SetErrorMode( SEM_FAILCRITICALERRORS ) ;

    if LENGTH(Root) = 1 then Root := Root + ":\\" ;
     Result := GetVolumeInformation( PCHAR( Root ), NIL,0,NIL, Dw1,Dw2, NIL,0 ) ;
     SetErrorMode( Oem ) ;

    end;

      3.检查驱动器A中磁盘是否有效

    type

     TDriveState = (DSNODISK, DSUNFORMATTEDDISK, DSEMPTYDISK, DSDISK_WITHFILES);
     ……
     function DriveState (driveletter: Char) : TDriveState;

     var

     mask: String[6];
     sRec: TSearchRec;
     oldMode: Cardinal;
     retcode: Integer;

    begin

     oldMode := SetErrorMode(SEM_FAILCRITICALERRORS);
     mask:= "?:\*.*";
     mask[1] := driveletter;
     {$I-}
     retcode := FindFirst (mask, faAnyfile, Srec);
     FindClose(Srec);
     {$I+}
     case retcode of
      0 : Result := DSDISK_WITHFILES; //磁盘有文件
      -18 : Result := DSEMPTYDISK; //好的空磁盘
      -21, -3: Result := DSNODISK; //NT,Win31的错误代号

     else

     Result := DSUNFORMATTEDDISK;
    end;

    4. 获取所有盘符和计算剩余

    procedure TFileForm.GetDisks;
      var
      str:string;
      Drivers:Integer;
      driver:char;
      i,temp,disksizee:integer;
      d1,d2,d3,d4: DWORD;


    begin

        Drivers:=GetLogicalDrives;
        temp:=(1 and Drivers);
        for i:=0 to 26 do
          begin
            if temp=1 then
              begin
                driver:=char(i+integer('A'));
                str:=driver+':';
                if (driver<>'') and (getdrivetype(pchar(str))<>drive_cdrom) and (getdrivetype(pchar(str))<>DRIVE_REMOVABLE) then
                begin
                  GetDiskFreeSpace(pchar(str),d1,d2,d3,d4);
                  lbxDisks.Items.Add(str+Format('-----------总空间: %f GB',[d4/1024/1024/1024*d2*d1])+Format('--------剩余空间: %f GB',[d3/1024/1024/1024*d2*d1]));
                end;
              end;
            drivers:=(drivers shr 1);
            temp:=(1 and Drivers);
          end;
      end;



     SetErrorMode(oldMode);

    end;

  • 相关阅读:
    数据切分——Atlas介绍
    HDU 5015 233Matrix (构造矩阵)
    Wincc操作数据库SQLSERVER
    UIWebView 设置背景为透明
    29个你必须知道的Linux命令
    【读书笔记】iOS-UIWindow-WindowLevel
    linux下uart应用编程
    Java Web HelloWorld!
    手把手图文教你eclipse下如何配置tomcat
    Tomcat安装及配置教程
  • 原文地址:https://www.cnblogs.com/smallmuda/p/1310772.html
Copyright © 2011-2022 走看看