Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: How to check to see if a CD drive is a writable on windows?

by terra incognita (Pilgrim)
on Oct 04, 2005 at 16:24 UTC ( [id://497314]=note: print w/replies, xml ) Need Help??


in reply to How to check to see if a CD drive is a writable on windows?

You can use Win32API to determine if the drive is writable by using the following code. The operation that you send to "DeviceIoControl" is "IOCTL_DISK_IS_WRITABLE" however there is no information about it so I had to go back to the C++ docs.
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, $uCre +ate, $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"; } }
I have tested this against a floppy with read/write and read only access set and it works correctly, however since I don't have a RW CDRom I can't test it further.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://497314]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-16 15:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found