Bilou_Gateux Posted August 22, 2006 Share Posted August 22, 2006 (edited) little script written to set a volatile environment variable RamDisk.using builtin WinXP/2003 Server fsutil.exe CLI tooland Vincent Fatica SetEnv.exe CLI tool@ECHO OFF&SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSIONcall :__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 forset volstring=RamDisk::#::# settings end::#::##############################::# make sure all external utilities are accessiblecall :__checkExtUtilsif "%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::#:__preinitset INST_ABORT=set INST_Dir=%~dp0set INST_Dir=%INST_Dir:~0,-1%set BIN_Dir=%~d0\bingoto :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 __checkExtUtilsErrorgoto :eof:__checkExtUtilsErrorecho Some of the external utilities are not accessible.echo Make sure you extracted the archive correctly and confirmecho that the utilities are in bin directory under rootset INST_ABORT=1goto :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 variableHow do i put Internet temporary Internet files on a RAM disk%SystemRoot%\system32\rundll32.exe setupapi,InstallHinfSection DefaultInstall 132 .\IEUSFLDR.INFIEUSFLDR.INF[Version]Signature = "$Windows NT$"[DefaultInstall]AddReg = AddRegDelReg = DelRegUpdateInis = 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 = 0x00000000REG_MULTI_SZ = 0x00010000REG_EXPAND_SZ = 0x00020000REG_BINARY = 0x00000001REG_DWORD = 0x00010001 Edited October 14, 2006 by Bilou_Gateux Link to comment Share on other sites More sharing options...
Br4tt3 Posted August 22, 2006 Share Posted August 22, 2006 Seems cool, gonna download it and check it out... bbl! Link to comment Share on other sites More sharing options...
Bilou_Gateux Posted August 22, 2006 Author Share Posted August 22, 2006 (edited) 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.2The 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: DrivesListI have a cleaner version of the original script which don't use temp files for parsing data.:DrivesList@echo offsetlocal ENABLEEXTENSIONS EnABLEDELAYEDEXPANSIONset Drive_Count=0set 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 offendlocal[edit]instead of'fsutil fsinfo drives^|more' command, use'fsutil fsinfo drives^|find /v ""'which don't require more utility[/edit] Edited September 29, 2007 by Bilou_Gateux Link to comment Share on other sites More sharing options...
Bilou_Gateux Posted August 13, 2008 Author Share Posted August 13, 2008 (edited) 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.exeSET 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=%~1IF "%~1"=="" (Set vlabel=RamDisk)call :__00000409Set L-Name=%0::# http://support.microsoft.com/kb/246011/en-us::# currently installed MUI languages: HKLM\SYSTEM\CurrentControlSet\Control\Nls\MUILanguages::# GetUserDefaultUILanguageFor /F "skip=1 delims= tokens=3" %%a in ('REG QUERY "HKCU\Control Panel\Desktop" /v MultiUILanguageId ^2^> Nul') Do call :__%%a:__DLFor /f %%# In ('Mountvol^|Findstr [d-z]:\\') Do ( Fsutil fsinfo drivetype %%#|Find /V "CD-ROM">Nul&&(Set "DL=%%~d#")&&call :__VN)goto :eof:__VNFor /f "tokens=2 delims=:" %%? in ('fsutil fsinfo volumeinfo %dl%^|Find /i %v%') Do ( (Set "VN=%%?")&&call :__VV)goto :eof:__VVfor %%? in (%VN%) do (set VN=%%?)rem (echo/%DL% "%VN%")if "%vn%"=="%vlabel%" call :__foundrem set vn=goto :eof:__foundcall :__checkExtUtils::# set volative environment variable RamDiskIf Not Defined EU Goto :__checkExtUtilsError(echo/%ExtUtilFName% -v %vn% %dl%)%EU% -v %vn% %dl%set vn=set dl=set vlabel=)goto :eof::##############################::#::# functions::#:__0000040cset desc="Gestion du volume" set v="Nom du Volume" set f="Lecteur fixe"set c="Lecteur de CD-ROM"goto :eof:__00000409set desc="Volume management"set v="Volume Name"set f="Fixed Drive"set c="CD-ROM Drive"goto :eof:__checkExtUtilsFor /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:__checkExtUtilsErrorecho 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=FRAand clean even more the code. Edited August 13, 2008 by Bilou_Gateux Link to comment Share on other sites More sharing options...
Bilou_Gateux Posted May 31, 2009 Author Share Posted May 31, 2009 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=FRAand clean even more the code.Temp.cmd@Echo off&Setlocal enableextensions::##############################::#::# REQUIRED: linkd utilitySET ExtUtilFName=linkd.exe::# "This command-line tool links an NTFS directory to a target object."::# ::##############################set DEBUG=1if "%DEBUG%"=="1" (set TRACE=echo) else (set TRACE=rem)%TRACE% Running script: %0call :__preinit(%ExtUtilFName% /? 2>&1) | FIND /I "Source" >NULIF ERRORLEVEL 1 call :__checkExtUtilsset vn=set dl=set vlabel=:Variables@Rem -------------------------------------------@Rem ! Variables@Rem ! You may edit or pass-in vlabel@Rem -------------------------------------------Set vlabel=%~1IF "%~1"=="" (Set vlabel=RamDisk):__Vset 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:__VVfor %%? in (%VN%) do (set VN=%%?)%TRACE% Volume Name: %VN%if "%vn%"=="%vlabel%" call :__foundrem set vn=goto :eof:__found(%ExtUtilFName% %temp% 2>&1) | FIND /I "is not linked" >NULIF ERRORLEVEL 1 goto :__checkExtUtilsErrorif not exist %dl%\Temp\NUL md %dl%\Temp(%TRACE% Linking Source %TEMP% to Target %dl%\Temp)%ExtUtilFName% %TEMP% %dl%\Tempset vn=set dl=set vlabel=set eu=)goto :eof::##############################::#::# functions::#:__preinitset INST_Dir=%~dp0set INST_Dir=%INST_Dir:~0,-1%set BIN_Dir=%~d0\bingoto :eof:__ParseDesc%TRACE% Parsing: %Desc%if not defined v set v=%Desc:~0,-1%&goto :EOFgoto :EOF:__checkExtUtils%TRACE% %ExtUtilFName% not found in PATH=%path%if exist %ExtUtilFName% copy /Y %ExtUtilFName% %SystemRoot%\system32 >NUL 2>&1goto :eof:__checkExtUtilsErrorecho Some of the external utilities are not accessible.echo Make sure you extracted the archive correctly and confirmecho that the utilities are in bin directory under rootPING 1.1.1.1 -n 2 -w 2222 > NUL 2>&1goto :eof::#::# functions end::#::############################## Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now