Hello,
is their a way to check in winbatch if a device is write locked or not.
Many thanks for your help!
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.
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
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:
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
Hello,
many thanks for your help. It works fine now!