了解知识
最近案子比较棘手,需要编写perl脚本 检测系统中SSD盘的逻辑盘符。
研究了大半天,搞定。
现同大家分享,以作共勉。
 
用perl 实现同win32 ::OnDeviceChange一样 获取系统中磁盘信息的功能:
 
#vicky finished by 10-03-13 22:10
#!/usr/bin/perl
#use Win32::kernel32;
use win32;
use win32::api;
use Win32API::File 0.08 qw( :ALL );
 
my $total_disk=GetLogicalDriveStrings(4*26+1,$osBuffer);
my $len=length $osBuffer;
print "$len- $osBuffer/n";
my $rec_diskinfo="*** logical disk info ***/n";
for(my $index=0;$index<$len; $index += 4)
{
 my $getdrive= substr($osBuffer, $index, 2);
 $rec_diskinfo .="$getdrive-->";
 my $type = GetDriveType($getdrive);
 if( $type==1)
    { $rec_diskinfo .="The root directory does not  exist/n";next; }
 if( $type==2){ $rec_diskinfo .="floppy drive/n";next; }
 if( $type==3){ $rec_diskinfo .="fixed drive/n"; $savdisk=$getdrive;next;}
 if( $type==4){ $rec_diskinfo .= "remote (network) drive/n";next; }
 if( $type==5){ $rec_diskinfo .="CD-ROM drive/n";next; }
 if( $type==6){ $rec_diskinfo .="A RAM disk/n";next; }
 if( $type<=0||$type>6){ $rec_diskinfo .= "UNKNOWN Disk/n";next; }
}
open DRVIF,">f://logicaldisk.inf"||die "can save logical disk info";
printf DRVIF $rec_diskinfo ;
close DRVIF;
 
 
PS:
 以上代码测试OK.
标签: perl
扩展知识