Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

batch script to determine hard disk

Posted on 2007-12-03
3
Medium Priority
?
753 Views
Last Modified: 2010-04-21
Hello Experts,

I'm writting a script to determine the fixed drives in a computer and put the output in a text file. There is a simple sample of my test but didn't work.

fsutil fsinfo drives|findstr /I /V "Units: " > c:\Units.txt
for /F "eol=; tokens=* delims= " %%i in (Units.txt) do fsutil fsinfo drivetype %%i|findstr /I /X "%%i- Fixed Drive" > HDisks.txt

Any help?? Thanks!
0
Comment
Question by:apendes
3 Comments
 
LVL 16

Expert Comment

by:gurutc
ID: 20394985
Hi,

Thinking about this question, I come up with a couple of conclusions, possibly wrong.

First, you probably won't have more than 4 physical drives to check, so you can limit your search to drives c: through f: or so.

Second, you can make sure you don't have a ton more local drives by checking the lastdrive environment variable.

Third, other options may be available, depending on whether this is true DOS or a command shell.

Fourth, brute force, ie change to each drive letter and check for an error-level condition.

Good Luck,

- gurutc
0
 
LVL 85

Accepted Solution

by:
oBdA earned 1000 total points
ID: 20395116
The output of "fsutil fsinfo drives" looks pretty neat, but is in fact everything else, because for whatever reason, it prints Chr(0) between the drives listed, which confuses "for /f".
Try the script below, which simply checks all drive letters if they're fixed.
@echo off
setlocal
set HDFile=HDisks.txt
if exist "%HDFile%" del "%HDFile%"
set DriveList=A: B: C: D: E: F: G: H: I: J: K: L: M: N: O: P: Q: R: S: T: U: V: W: X: Y: Z:
for %%a in (%DriveList%) do (
  echo Checking %%a ...
  fsutil fsinfo drivetype %%a | find /i "Fixed Drive" >NUL
  if not errorlevel 1 (
    >>"%HDFile%" echo %%a
    echo %%a
  )
)

Open in new window

0
 

Author Closing Comment

by:apendes
ID: 31412301
Its a very clear method to acomplish my request.
Thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Screencast - Getting to Know the Pipeline
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question