Jump to content

Volume Name & Drive Letter, fsutil, setenv, ramdisk


 Share

Recommended Posts

little script written to set a volatile environment variable RamDisk.

using builtin WinXP/2003 Server fsutil.exe CLI tool

and Vincent Fatica SetEnv.exe CLI tool

@ECHO OFF&SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
call :__preinit

::##############################
::#
::# settings: here are some settings that might need to be set up before using this for the first time
::#
::# set the volume name to search for
set volstring=RamDisk
::#
::# settings end
::#
::##############################

::# make sure all external utilities are accessible
call :__checkExtUtils
if "%INST_ABORT%" == "1" exit /b 1

::# http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/fsutil.mspx
::# fsutil (WinXP/2003 Server)
for /f "skip=1 tokens=1*" %%i in ('fsutil fsinfo drives^|more') do (
set dl=%%i
for /f "tokens=2* delims=:" %%j in ('fsutil fsinfo volumeinfo %%i^|find /i "Volume Name"') do (
::# Remove trailing reverse solidus
if "!dl:~-1!"=="\" (set dl=!dl:~0,-1!)
::# Remove leading and trailing spaces if any
for %%k in (%%j) do SET vn=%%k
)
::# Debug infos
echo/Drive Letter: !dl! Volume Name: !vn!
::# Function call
if "!vn!"=="%volstring%" call :__found
)
goto :eof

::##############################
::#
::# functions
::#

:__preinit
set INST_ABORT=
set INST_Dir=%~dp0
set INST_Dir=%INST_Dir:~0,-1%
set BIN_Dir=%~d0\bin
goto :eof

:__checkExtUtils
::# make sure external utils are accessible and throw an error if not
::# http://barnyard.syr.edu/~vefatica/
::# setenv set environment variables
%BIN_Dir%\setenv -u Temp >nul 2>&1 || goto __checkExtUtilsError
goto :eof

:__checkExtUtilsError
echo Some of the external utilities are not accessible.
echo Make sure you extracted the archive correctly and confirm
echo that the utilities are in bin directory under root
set INST_ABORT=1
goto :eof

:__found
::# set volative environment variable RamDisk
%BIN_Dir%\setenv -v !vn! !dl!
set vn=
goto :eof

::#
::# functions end
::#
::##############################

and example usage of this volatile environment variable

How do i put Internet temporary Internet files on a RAM disk

%SystemRoot%\system32\rundll32.exe setupapi,InstallHinfSection DefaultInstall 132 .\IEUSFLDR.INF

IEUSFLDR.INF

[Version]
Signature = "$Windows NT$"

[DefaultInstall]
AddReg = AddReg
DelReg = DelReg
UpdateInis = UpdateInis

[AddReg]
HKCU,"Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders","Cache",%REG_EXPAND_SZ%,"%RAMDISK%\Documents and Settings\%UserName%\Local Settings\Temporary Internet Files"
HKCU,"Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders","Cookies",%REG_EXPAND_SZ%,"%RAMDISK%\Documents and Settings\%UserName%\Cookies"
HKCU,"Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders","History",%REG_EXPAND_SZ%,"%RAMDISK%\Documents and Settings\%UserName%\Local Settings\History"



[DelReg]

[UpdateInis]

[Strings]

;
; Non-localizable strings
;

REG_SZ = 0x00000000
REG_MULTI_SZ = 0x00010000
REG_EXPAND_SZ = 0x00020000
REG_BINARY = 0x00000001
REG_DWORD = 0x00010001

Edited by Bilou_Gateux
Link to comment
Share on other sites


For the purpose of putting Internet temporary files on a RAM disk, you can use:

Free RAMDisk for Windows 2000 / Windows XP / Windows Server 2003 version 5.0.2.2

The size is limited to 64 Mb, large enough to browse the web.

For downloading huge files, a download manager is mandatory. Otherwise the size of downloadable file is limited by the free space available in the RAM disk if IE is used.

How to install QSoft RAMdisk unattended here

+------------------------------------------------------------------------------------------------------+

My script is written from an original idea found here: DrivesList

I have a cleaner version of the original script which don't use temp files for parsing data.

:DrivesList
@echo off
setlocal ENABLEEXTENSIONS EnABLEDELAYEDEXPANSION
set Drive_Count=0
set DrivesList=

for /f "skip=1 TOKENS=1*" %%i in ('fsutil fsinfo drives^|more') do (
set Drive=%%i
set /a Drive_Count+=1

for /F "tokens=1* delims=- " %%A in ('fsutil fsinfo drivetype !Drive!^|find "-"') do (
echo Drive !Drive_Count!: [!Drive:~0,1! ] %%B
set MountPoint_Count=
for /F "tokens=* delims=:" %%Z in ('Mountvol^|find "!Drive:~0,1!:\"') do (
set MountPoint=%%Z
if !MountPoint:~8! NEQ !Drive! (
set /a Drive_Count+=1
set /a MountPoint_Count+=1
echo MountPoint !Drive_Count!: [!MountPoint:~8,1!!MountPoint_Count!] !MountPoint:~8!
set MountPoint[!Drive:~0,1!]=MountPoint_Count
)
)
set Drive[!Drive:~0,1!]=%%B !MountPoint_Count!
set DrivesList=!DrivesList! !Drive:~0,1!!MountPoint_Count!
)
)
rem echo Drive[q] [%Drive[q]%]
echo dl: %DrivesList%
echo off
endlocal

[edit]

instead of

'fsutil fsinfo drives^|more'

command, use

'fsutil fsinfo drives^|find /v ""'

which don't require more utility

[/edit]

Edited by Bilou_Gateux
Link to comment
Share on other sites

  • 1 year later...

Thanks to Yzöwl code posted here, i have rewritten a - little - much cleaner script:

@Echo off&Setlocal enableextensions

::##############################
::#
::# REQUIRED External Utility
::#
::# http://barnyard.syr.edu/~vefatica/
::#
SET ExtUtilFName=setenv.exe
SET ExtUtilDesc="set environment variables"
::#
::##############################

set vn=
set dl=
set vlabel=

:Variables
@Rem -------------------------------------------
@Rem ! Variables
@Rem ! You may edit or pass-in vlabel
@Rem -------------------------------------------
Set vlabel=%~1
IF "%~1"=="" (Set vlabel=RamDisk)
call :__00000409

Set L-Name=%0

::# http://support.microsoft.com/kb/246011/en-us
::# currently installed MUI languages: HKLM\SYSTEM\CurrentControlSet\Control\Nls\MUILanguages
::# GetUserDefaultUILanguage
For /F "skip=1 delims= tokens=3" %%a in ('REG QUERY "HKCU\Control Panel\Desktop" /v MultiUILanguageId ^2^> Nul') Do call :__%%a

:__DL
For /f %%# In ('Mountvol^|Findstr [d-z]:\\') Do (
Fsutil fsinfo drivetype %%#|Find /V "CD-ROM">Nul&&(Set "DL=%%~d#")&&call :__VN)
goto :eof

:__VN
For /f "tokens=2 delims=:" %%? in ('fsutil fsinfo volumeinfo %dl%^|Find /i %v%') Do (
(Set "VN=%%?")&&call :__VV)
goto :eof

:__VV
for %%? in (%VN%) do (set VN=%%?)
rem (echo/%DL% "%VN%")
if "%vn%"=="%vlabel%" call :__found
rem set vn=
goto :eof

:__found
call :__checkExtUtils
::# set volative environment variable RamDisk
If Not Defined EU Goto :__checkExtUtilsError
(echo/%ExtUtilFName% -v %vn% %dl%)
%EU% -v %vn% %dl%
set vn=
set dl=
set vlabel=
)
goto :eof


::##############################
::#
::# functions
::#

:__0000040c
set desc="Gestion du volume"
set v="Nom du Volume"
set f="Lecteur fixe"
set c="Lecteur de CD-ROM"
goto :eof

:__00000409
set desc="Volume management"
set v="Volume Name"
set f="Fixed Drive"
set c="CD-ROM Drive"
goto :eof

:__checkExtUtils
For /f "tokens=*" %%# in ('dir /a /s /b %~d0\%ExtUtilFName% ^2^> Nul') Do (
(Set "EU=%%~fs#")&&%%~fs# -u Temp >nul 2>&1 || goto __checkExtUtilsError
)
goto :eof

:__checkExtUtilsError
echo Some of the external utilities are not accessible.
goto :eof

::#
::# functions end
::#
::##############################

I would like to avoid to set %v% variable dependent of MUI language set. Currently, there is support only for only 0409=ENU and 040C=FRA

and clean even more the code.

Edited by Bilou_Gateux
Link to comment
Share on other sites

  • 9 months later...
I would like to avoid to set %v% variable dependent of MUI language set. Currently, there is support only for only 0409=ENU and 040C=FRA

and clean even more the code.

Temp.cmd

@Echo off&Setlocal enableextensions

::##############################
::#
::# REQUIRED: linkd utility
SET ExtUtilFName=linkd.exe
::# "This command-line tool links an NTFS directory to a target object."
::#
::##############################

set DEBUG=1
if "%DEBUG%"=="1" (set TRACE=echo) else (set TRACE=rem)
%TRACE% Running script: %0

call :__preinit
(%ExtUtilFName% /? 2>&1) | FIND /I "Source" >NUL
IF ERRORLEVEL 1 call :__checkExtUtils

set vn=
set dl=
set vlabel=

:Variables
@Rem -------------------------------------------
@Rem ! Variables
@Rem ! You may edit or pass-in vlabel
@Rem -------------------------------------------
Set vlabel=%~1
IF "%~1"=="" (Set vlabel=RamDisk)

:__V
set v=
For /f "tokens=1* delims=:" %%? in ('fsutil fsinfo volumeinfo %SystemDrive%\ ^|Find ":"') Do (
(Set "Desc=%%?")&&call :__ParseDesc
if defined v goto :__DL)

:__DL
%TRACE% Search for text string: %v%
For /f %%# In ('Mountvol^|Findstr [d-z]:\\') Do (
Fsutil fsinfo drivetype %%#|Find /V "CD-ROM">Nul&&(Set "DL=%%~d#")&&call :__VN)
goto :eof

:__VN
%TRACE% Drive Letter: %DL%
For /f "tokens=2 delims=:" %%? in ('fsutil fsinfo volumeinfo %dl%\ ^|Find /i "%v%"') Do (
(Set "VN=%%?")&&call :__VV)
goto :eof

:__VV
for %%? in (%VN%) do (set VN=%%?)
%TRACE% Volume Name: %VN%
if "%vn%"=="%vlabel%" call :__found
rem set vn=
goto :eof

:__found
(%ExtUtilFName% %temp% 2>&1) | FIND /I "is not linked" >NUL
IF ERRORLEVEL 1 goto :__checkExtUtilsError
if not exist %dl%\Temp\NUL md %dl%\Temp
(%TRACE% Linking Source %TEMP% to Target %dl%\Temp)
%ExtUtilFName% %TEMP% %dl%\Temp
set vn=
set dl=
set vlabel=
set eu=
)
goto :eof


::##############################
::#
::# functions
::#

:__preinit
set INST_Dir=%~dp0
set INST_Dir=%INST_Dir:~0,-1%
set BIN_Dir=%~d0\bin
goto :eof

:__ParseDesc
%TRACE% Parsing: %Desc%
if not defined v set v=%Desc:~0,-1%&goto :EOF
goto :EOF

:__checkExtUtils
%TRACE% %ExtUtilFName% not found in PATH=%path%
if exist %ExtUtilFName% copy /Y %ExtUtilFName% %SystemRoot%\system32 >NUL 2>&1
goto :eof

:__checkExtUtilsError
echo Some of the external utilities are not accessible.
echo Make sure you extracted the archive correctly and confirm
echo that the utilities are in bin directory under root
PING 1.1.1.1 -n 2 -w 2222 > NUL 2>&1
goto :eof

::#
::# functions end
::#
::##############################

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.


×
×
  • Create New...