Solved

batch script to determine hard disk

Posted on 2007-12-03
3
745 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 83

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

822 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