WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: si20596 on April 07, 2016, 11:18:10 PM

Title: device write locked...
Post by: si20596 on April 07, 2016, 11:18:10 PM
Hello,

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

Many thanks for your help!
Title: Re: device write locked...
Post by: td on April 08, 2016, 06:45:06 AM
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.
Title: Re: device write locked...
Post by: si20596 on April 08, 2016, 08:52:17 AM
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

Title: Re: device write locked...
Post by: td on April 08, 2016, 10:12:38 AM
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
 
Title: Re: device write locked...
Post by: si20596 on April 11, 2016, 07:08:53 AM
Hello,

many thanks for your help. It works fine now!