device write locked...

Started by si20596, April 07, 2016, 11:18:10 PM

Previous topic - Next topic

si20596

Hello,

is their a way to check in winbatch if a device is write locked or not.

Many thanks for your help!

td

What 'device' are you referring to and what type of lock are you referring too?   Are you referring to a USB flash drive with a mechanical lock or are you referring to a device with file permission settings?  The usual approach to testing for the ability to write to a device hosting a file system is to just try it and see if you get an error.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

si20596

Hello,

at the moment I will test it with a USB drive with a mechanical lock. When I activate it, I see an error message from me, but I will check the error status. Windows list me the device is currently write protected.

ErrorMode(@OFF)
WrtFil = FileOpen(DataFile,"Write")
ErrorMode(@CANCEL)

if WrtFil == @FALSE then ...

I will check the device first... Is this write protected, I have no space on the disk or no permissions to write...
DiskVolInfo, DiskScan or DiskInfo...

Many thanks for your feedback


td

If you are interested in determining a specific reason why a drive is not writable instead of just whether or not you can write to it then one approach involves using WMI to determine the current device access.  For example:
Code (winbatch) Select
RemovableDisk  = 2
strComputer = "."
objWMIService = GetObject('winmgmts:{impersonationLevel=impersonate}!\\':strComputer:'\root\cimv2')
colDisks = objWMIService.ExecQuery(:'SELECT * FROM Win32_LogicalDisk WHERE DriveType = "':RemovableDisk:'"')
ForEach objDisk in colDisks
   vtAccess = objDisk.Access
   if ObjectTypeGet(vtAccess) == 'NULL'
      strAccess = 'information unavailable'
   else
      strAccess = ''   
      switch vtAccess
      case 1
         strAccess = 'Readable'
         break;
      case 2
         strAccess = 'Writable'
         break
      case 3
         strAccess = 'Read/Write'
         break
      case 4
         strAccess = 'Write Once'
         break
      case vtAccess
         strAccess = '<Unknown>'
         break
      endswitch
   endif   
   Pause('Drive ':objDisk.DeviceID, 'Access ':strAccess)
Nextt
 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

si20596

Hello,

many thanks for your help. It works fine now!