January 27, 200818 yr hey guys here's what i wanna do : i have somethings related with the existance of the D:\ partition. that is i need a cmd format which check if a D:\ partition exist, if so then apply or run any other command if not then it will ignore. example:if D:\ partition exist then move "my documents" folder to D:\my documents. if not exist then ignore or do nothing. in this example i may change "move my documents folder" command with any other D:partition related commands so i need a template. it must be something like belowif exist D:\then start %CDROM%\mydocs.cmdif not >nullcan you help me about this template please.thanks in advance
January 27, 200818 yr Here is a template for you to use. You will have to add what ever you need to the function called Work@Echo OffCLSColor 9fMode 55,11If Exist D: Goto WorkIf Not Exist D: Goto Quit:: Place What Ever Coding You Need Below Work:WorkCLS Echo.Echo Found D Drive Preparing Next Cmdping -n 4 127.0.0.1>nulGoto TheEnd:QuitCLS Echo.Echo Missing D Drive Exiting Cmdping -n 4 127.0.0.1>nulExit:TheEndExit
January 27, 200818 yr Basic Examplemountvol|find "D:\">nul&&<place your command here>Depending upon the exact use required, there may be a problem with the above solutions!D: may exist but may be allocated to a non-writable or non-fixed drive! Not the most appropriate of places to be trying to issue a move command to for instance.
January 27, 200818 yr Create a vb script (I called it t.vbs)On Error Resume Nextconst wbemFlagReturnImmediately = &h10const wbemFlagForwardOnly = &h20set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)for each objItem In colItems WScript.Echo "Found " & objItem.Name & " " & objItem.Description if objItem.Name = "D:" then WScript.Echo "Drive type is " & objItem.Description if objItem.DriveType=3 then WScript.Quit(0) 'This is a Local Fixed Disk else WScript.Quit(1) 'D: is not a Local Fixed Disk no need to continue end if end ifnextWScript.Quit(1)Call this from a batch file and use the return value.@echo offcscript -nologo "%~dp0t.vbs"if not errorlevel 1 ( echo Moving my documents to the D: drive)You could also modify the script to use WshShell.Run to directly call a batch file.set WshShell = WScript.CreateObject("WScript.Shell")WshShell.Run(strCommand, [intWindowStyle], [bWaitOnReturn]) Note: You will also need to modify the "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Personal" registry key so Windows knows where you put the My Documents folder. Edited January 27, 200818 yr by FrankE9999
January 27, 200818 yr Author @gunsmokingman @Yzöwli knew that i can trust you :=) you have helped me before. thank you very much for replies. they worked.@FrankE9999i also thank you but vbs scripts are not as familiar as cmd scripts so i allways prefer cmd scripts. thanks a lot anyway.
January 27, 200818 yr I would check for the existing of D:\nul.ext :http://msmvps.com/blogs/martinzugec/archiv...-same-name.aspxhttp://xset.tripod.com/tip5.htmit works with mounted drives too.However, as always best method is Yzöwl's one, I may add that what I would do is to also try "probing" destination drive, using a "tagfile" like in:@ECHO OFFIF %1.==. ECHO NO PARAMETER SUPPLIED&GOTO :EOFSET Targetdrive=%1ECHO tagfile > %~d0\tagfile.tagcopy /y %~d0\tagfile.tag %~d1>nul 2>&1IF %ERRORLEVEL% NEQ 0 (ECHO ERROR DRIVE %~d1 NOT RESPONDING, ERROR!) ELSE (ECHO ERROR DRIVE %~d1 IS RESPONDING, OK!)IF EXIST %~d1\tagfile.tag del %~d1\tagfile.tagIF EXIST %~d0\tagfile.tag del %~d0\tagfile.tag(this example must be run from a R/W enabled drive )jaclaz
January 27, 200818 yr If you are running under an Administrator account you could always extend the line I gave to check for the type of drive too.Mountvol|Find "D:\">Nul&&(FSUtil FSInfo DriveType D:|Find "Fixed Drive">Nul 2>&1&&(<place your command here>))Which could then be reduced due to the nature of the FSUtil command to this single line:FSUtil FSInfo DriveType D:|Find "Fixed Drive">Nul 2>&1&&<place your command here>I would check for the existing of D:\nul.ext :http://msmvps.com/blogs/martinzugec/archiv...-same-name.aspxNot really relevant to the thread but thanks for the reminder to read Martins blog, I haven't seen much of him around here for some time!
January 28, 200818 yr Which could then be reduced due to the nature of the FSUtil command to this single line:FSUtil FSInfo DriveType D:|Find "Fixed Drive">Nul 2>&1&&<place your command here>Will have a look at this to see if I can put this to good use. I would like to redirect the folder My Documents to another drive. I could use this script for this purpose perhaps. Nice, thank you!
February 15, 200818 yr I would like to ask batch expert to improve my script. Most parts are copy and paste from others scripts and probably not optimized!I use it to set %temp% to a temp folder on Ramdisk drive.to find the Ramdisk drive, i check Volume Name rather than Drive Letter because sometime i set Drive Letter to R: and sometime to Z:i call it with:FindRD.cmd RamDisk@ECHO OFF&SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSIONcall :__preinitset vn=set dl=:Variables@Rem -------------------------------------------@Rem ! Variables@Rem ! You may edit or pass-in vlabel@Rem -------------------------------------------Set vlabel=%1Set L-Name=%0For /F "skip=1 delims= tokens=3" %%a in ('REG QUERY "HKCU\Control Panel\Desktop" /v MultiUILanguageId ^2^> Nul') do call :__%%a::# 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 "tokens=*" %%i in ('fsutil fsinfo drives ^| FIND /V ""') DO ( set dl=%%i SET dl=!dl:~-3,3! for /f "tokens=2* delims=:" %%j in ('fsutil fsinfo volumeinfo !dl!^|find /i %v%') 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 for /f "tokens=2* delims=-" %%j in ('fsutil fsinfo drivetype !dl! ^| FIND /V "CD-ROM"') do (echo/%f% = !dl! %v%= !vn!) ::# Function call if "!vn!"=="%vlabel%" call :__found set vn=)goto :eof::##############################::#::# functions::#:__preinitset INST_ABORT=set INST_Dir=%~dp0set INST_Dir=%INST_Dir:~0,-1%set BIN_Dir=%~d0\bingoto :eof:__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:__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!@Echo ! ----------------------------------------echo volative environment variable !vn! set to !dl!set vn=goto :eof::#::# functions end::#::##############################
Create an account or sign in to comment