Check if drive is writable windows API function [closed]
Question
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!
Solution
Try calling SetErrorMode( SEM_FAILCRITICALERRORS)
to prevent the error messageboxes from popping up.
http://msdn.microsoft.com/en-us/library/ms680621(VS.85).aspx
OTHER TIPS
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 ;-)
Call GetVolumeInformation() and check FILE_READ_ONLY_VOLUME
in the returned flags parameter.