Different behavior between Windows XP and Vista

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Diego Queiroz
Posts: 2
Joined: 25 Sep 2009 17:29

Different behavior between Windows XP and Vista

#1 Post by Diego Queiroz » 25 Sep 2009 17:47

Hello everybody.

I got two computers, one running Windows Vista x64 SP2 and other running Windows XP x86 SP3, and I am experiencing one different behavior between my operating systems.

The problem is exactly in this line of code:

Code: Select all

fsutil fsinfo drives | find /v ""


If you run it on a Windows XP terminal you get this result:

Code: Select all

Drives: A:\
C:\
D:\
E:\
F:\


But if you run it on Windows Vista terminal you get this result:

Code: Select all

Drives: A:\ C:\ D:\ E:\ F:\


I really don't know if this issue is related only with the 64bit version of Windows Vista (I do not have a 32bit installation to test at this moment), but I know that this is because of the fsutil program. In older versions it returns a null character between driver names (what probally is a bug), but on Vista x64 this issue was "fixed".


Now I want to split the output of "fsutil fsinfo drives" into lines but I don't know how. :-(

Can someone help me?
Any help is appreciated.


Regards,

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 28 Sep 2009 11:11

Don't have Vista to try with, but we've gotten NT and XP to work using this:

setlocal enabledelayedexpansion
for /f "usebackq tokens=1*" %%a in (`FSUTIL FSINFO DRIVES ^| find ":"`) do (
if /i "%%a" NEQ "Drives:" (
set drives=%%a !drives!
) else (
if not 1%%b==1 set drives=%%b !drives!
)
)

Makes the variable drives contain a space delimited list of the drives returned by fsutil. Manipulate that variable as you wish (like, say, with a for loop).

Here's a full code I've written to find an unused drive letter:

Code: Select all

    :: Version 0.2
    :: This file will echo a free drive letter.  It will also set a variable
    :: to that drive letter if it is passed the variable name like this:
    :: freedrv variablename

@setlocal enabledelayedexpansion
@echo off
set freedrv_drives=
for /f "usebackq tokens=1*" %%a in (`FSUTIL FSINFO DRIVES ^| find ":"`) do (
   if /i "%%a" NEQ "Drives:" (
      set freedrv_drives=%%a !freedrv_drives!
      ) else (
         if not 1%%b==1 set freedrv_drives=%%b !freedrv_drives!
   )
)
call :process
endlocal && echo %freedrv_drive%&&if not 1%1==1 set %1=%freedrv_drive%
goto :eof

:process
for %%a in (z y x w v u t s r q p o n m l k j i h g f) do (
   echo %freedrv_drives% | find /i "%%a:\" >nul 2>nul
   if errorlevel 1 (
      set freedrv_drive=%%a
      exit /b
   )
)
goto :eof

Diego Queiroz
Posts: 2
Joined: 25 Sep 2009 17:29

#3 Post by Diego Queiroz » 28 Sep 2009 14:01

Hello avery_larry.

Thanks for your reply.

As I said, this behavior happens only with Windows Vista so, as expected, your code does not work on it (remembering: I am talking about the 64bit version of Windows Vista. I did not tested this issue on the 32bit version).

I'll write a program to read the output from "fsutil" to split it in lines. At this moment, I think this is the safer way to do what I want in both operating systems.

Anyway, I am still looking for help.


Regards,

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#4 Post by avery_larry » 28 Sep 2009 16:05

If those are true spaces, then try this:

Code: Select all

for /f "tokens=2-27 delims= " %%a in ('fsutil fsinfo drives') do (
   if not "%%a"=="" echo %%a
   if not "%%b"=="" echo %%b
   if not "%%c"=="" echo %%c
   if not "%%d"=="" echo %%d
   if not "%%e"=="" echo %%e
   if not "%%f"=="" echo %%f
   if not "%%g"=="" echo %%g
   if not "%%h"=="" echo %%h
   if not "%%i"=="" echo %%i
   if not "%%j"=="" echo %%j
   if not "%%k"=="" echo %%k


...  all the way to z

)



Or (with less code) this:

Code: Select all

@echo off
for /f "tokens=1* delims= " %%a in ('fsutil fsinfo drives') do call :process %%b
goto :eof


:process
echo %1
shift
if not "%1"=="" for /f "tokens=1* delims= " %%a in ("%*")do call :process %%b
goto :eof

Post Reply