共勉:perl实现同win32 ::OnDeviceChange一样的功能

lhy2199 lhy2199 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
用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;



本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lhy2199/archive/2010/03/13/5377573.aspx
...全文
评论 1
收藏 已收藏
分享
返回顶部
lhy2199
脚本语言 37,737 成员 34,208 内容