use strict; use warnings; use Win32API::File 0.08 qw( :ALL ); my $sRootPath = "d:/"; if(GetDriveType( $sRootPath ) == 5){ # then this is a CD-ROM my $sPath = "//./D:"; my $uAccess = 0; my $uShare = FILE_SHARE_READ(); my $pSecAttr = []; my $uCreate = OPEN_ALWAYS(); my $uFlags = 0; my $hModel = 0; my $hDisk= CreateFile( $sPath, $uAccess, $uShare, $pSecAttr, $uCreate, $uFlags, $hModel) or die "Can't read attributes of $sPath: $^E\n"; my $controlcode = IOCTL_DISK_IS_WRITABLE; my $inbuff = []; my $inbuffsz = 0 ; my $outbuff = []; my $outbuffsz = 0; my @bytesret = []; my $overlap = []; if (DeviceIoControl($hDisk,$controlcode,$inbuff,$inbuffsz,$outbuff,$outbuffsz,@bytesret,$overlap)){ print "Status = device is write enabled\n"; }else{ print "Status = $^E\n"; } }