Check if drive is writable windows API function

1.3k views Asked by At

Hello is there any windows API function that would return if drive is writable. Sometimes drive is visible under drives but when trying to programaticly write to it, it gives you a msg box error wich freezes the application until user presses the ok button. Is there any built in function that would check if drive is writable without the annoying error box?

I tried trycopy already and returns the same msgbox error :(

Thanks!

3

There are 3 answers

0
Dave On BEST ANSWER

Try calling SetErrorMode( SEM_FAILCRITICALERRORS) to prevent the error messageboxes from popping up.

http://msdn.microsoft.com/en-us/library/ms680621(VS.85).aspx

0
Dabblernl On

You can set a reference to Microsoft Scripting Runtime.

You can then use code like:

Dim FSO as New FileSystemObject
Dim clsDrive as Scripting.Drive

Set clsDrive=FSO.GetDrive("C")

The Drive class has a FreeSpace Property, which will be zero if the drive is not writeable.

Moreover there is a Scripting.Folder class that you can het by using FSO.GetFolder() that has an Attributes property, which consists of flags of type FileAttribute. You can use code like

clsFolder.Attributes And FileAttribute.Readonly to check for err... ReadOnlyness ;-)

0
Angstrom On

Call GetVolumeInformation() and check FILE_READ_ONLY_VOLUME in the returned flags parameter.