DELPHI 通过U盘方式加密


本文整理自网络,侵删。

 1.检查是否是U盘

2.查检U盘的卷标

3.通过VolumeLable的返回值对比判断是否你加密的U盘(卷标要定义好)



function CheckUsbDisk(FLable:string):Boolean; //检验是否是USB优盘
var
Drive: Integer;
DriveLetter: Char;
begin
Result :=false;
for Drive := 2 to 25 do
begin
DriveLetter := Chr(Drive + ord('A'));
if GetDrivetype(PChar(DriveLetter+':\'))= DRIVE_REMOVABLE then
begin
if VolumeID(DriveLetter)=FLable then
begin
Result :=true;
exit;
end;
end;
end;
end;

function VolumeLable(DriveChar: Char): string; //检验USB优盘的卷标
var
OldErrorMode: Integer;
NotUsed, VolFlags: DWORD;
Buf: array [0..MAX_PATH] of Char;
begin
OldErrorMode := SetErrorMode(SEM_FAILCRITICALERRORS);
try
Buf[0] := #$00;
if GetVolumeInformation(PChar(DriveChar + ':\'), Buf, DWORD(sizeof(Buf)),
nil, NotUsed, VolFlags, nil, 0) then
SetString(Result, Buf, StrLen(Buf))
else Result := '';
if DriveChar < 'a' then
Result := AnsiUpperCaseFileName(Result)
else
Result := AnsiLowerCaseFileName(Result);
Result := Format('%s',[Result]);
finally
SetErrorMode(OldErrorMode);
end;
end;

相关阅读 >>

Delphi tstringlist utf8编码保存并开启bom

Delphi serial number of an usb flash drive 获取u盘硬件序列号

Delphi xe7检查android蓝牙权限

Delphi 进程隐藏的若干方法

获取 ip138 ip 地址

Delphi cannot find implementation of method formcreate 解决办法

Delphi 根据盘符弹出u盘

Delphi 安卓app的http访问权限

Delphi 获取其他进程句柄的几种方法

Delphi 如何将整数值转换为罗马数字表示形式

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...

    暂无评论...