Computing.Net > Forums > Disk Operating System > Batch: Chk. for write protec. media

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch: Chk. for write protec. media

Reply to Message Icon

Name: Soeren
Date: May 28, 2003 at 11:15:05 Pacific
OS: WinMe DOS
CPU/Ram: N/A
Comment:

Does any of you gyus know a way to check if a
medie (HD - MO - Floppy) is write protected?

Have tryed...
- ECHO "bla-bla" > Media\test.tst
- DIR media\*.* > media\test.tst

and then try to trap an errorlevel on that,
but no change i errorlevel.

I know that OS gives a nice warning, but I
have to have it in errorlevel or variabel.

Hope one of you BRAINS can help

Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: May 29, 2003 at 16:02:27 Pacific
Reply:

The following script was extracted from Laurence Soucy's Batchfiles FAQ and slightly addapted. It will check if a certain drive is valid AND writeable:

:: Check if drive %1 is valid and writable
:: %1 is the drive letter without colon
@echo off
ctty nul
%comspec%/f/cDIR/ADH/W/-P %1: |FIND ":\"> nul
if errorlevel=1 goto no_drive
echo writeable> %temp%.\t1.tmp
%comspec%/f/cCOPY /Y %temp%.\t1.tmp %1:\~¥1.tmp
del %temp%.\t1.tmp
ctty con
if exist %1:\~¥1.tmp goto write_ok
echo drive %1 not writeable
goto end

:write_ok
del %1:\~¥1.tmp
echo drive %1 writeable
goto end

:no_drive
ctty con
echo drive %1 invalid

:end

Note 1: I've tested that script on Win98SE and it works as intended. So, it is very likely to work on WinME, though that's not for sure.

Note 2: the /F switch for command.com is undocumented, and will automatically answer Fail to the questions "Retry Abort or Fail?".

Note 3: the switches on the DIR command (third code line) are to reduce the number of lines to be processed by FIND.exe.

The script might look a little bit more complex than you expected, but it's not that simple handling those error messages that could occur if the drive is not valid or writeable (bypassing such messages and supressing them).

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br

_________________________________________________________


0

Response Number 2
Name: Wengier
Date: May 30, 2003 at 17:02:33 Pacific
Reply:

Or, you just use the following command to check that:

DREADY A: /W
IF ERRORLEVEL 1 IF NOT ERRORLEVEL 2 ECHO Disk A is write-protected!


0

Response Number 3
Name: Secret_Doom
Date: May 30, 2003 at 17:10:08 Pacific
Reply:

It is obviously easier to perform the task using a external 3rd party application. The batch script I posted is so much more complex then Wengier's because it does not require any 3rd party apps, which means it should work on any regular Win9x environment (and probably on WinMEs environments as well).

-- Leonardo Pigntaro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Response Number 4
Name: Søren
Date: May 31, 2003 at 12:29:33 Pacific
Reply:

As -- Leonardo Pigntaro - Secret_Doom --
stated, I will try to avoid 3rd party appl.
Foremost because I have to document each little file with a GAMP
(Good Manufacturing Practice) SMS
(Software Module Specification)document which
includes Functional & Design Specifications and a FAT (Factory Acceptance Testing) Protocol - Testplan and testpapers.
(Are you out of breath?).

My problem with Leonardo´s proposal, is that
I only have one drive to write to (the one being checked. All other drives is NTFS.
I will load NTFSDOS (not NTFSPRO) so I am able to read the drives, but not write to them.
That means that when trying to make temp. file tmp1.tmp, the computer latches up, and has to be rebooted.
I am still cheewing on whether I can work around this problem.

Any suggestions?

And thanks to both of you.


0

Response Number 5
Name: Søren
Date: May 31, 2003 at 14:21:46 Pacific
Reply:

Well.
Im done testing Leonardo Pigntaro - Secret_Doom´s suggestion on Win98SE and WinMe With %temp% writable (C:\Windows\temp).

Win98SE: Works as intended.
WinMe...
- Check for valid drive: OK
- Drive %1 not write protected: OK
- Drive %1 write protected: computer latches
up. Reboot nessesary, must be one of the
used command.com switches.

I have still the problem of only having %1
to write to. Dont know were to go from here.


0

Related Posts