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;

  • 相关阅读:
    linux(fedora) 下dvwa 建筑环境
    【ThinkingInC++】2、输入和输出流
    Caused by: java.lang.ClassNotFoundException: javax.transaction.TransactionManager
    SpringMVC注释启用
    XML wsdl soap xslt xsl ide
    一个解析RTSP 的URL函数
    PHP:header()函数
    jquery实现鼠标焦点十字效果
    拼出漂亮的表格
    Oracle中如何插入特殊字符:& 和 ' (多种解决方案)
  • 原文地址:https://www.cnblogs.com/smallmuda/p/1310772.html
Copyright © 2011-2022 走看看