Solved

batch script to determine hard disk

Posted on 2007-12-03
3
750 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 250 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

623 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