• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Batch Question: FOR

#1
I'm trying to figure out the following. In the end I want the script to be detecting all mounted drives and running designated programs on them.
Code:
IF "HKLM\SYSTEM\MountedDevices" /v "\DosDevices\C:"=="5c ?" set Cdrive=0
Where "5c ?" is a hex value and 5c is the first term, if that term is 5c then the drive is not mounted. If another term is there, then the drive is mounted. I figure if I query each possible drive from C-Z in this way I can then do something like:
Code:
if "%Cdrive%"=="1" run program C: /switch
And so on down through to Z.

Mounted Drive info is stored in "HKLM\SYSTEM\MountedDevices".

Anyone have suggestions on a better way I'd love to hear it.

/edit
I've come up with an alternative, instead of using the registry entry as a flag, I'll use the "Recycler" folder created on all drives.
 
#3
I needed it for my Maintenance Routine Script, and since I don't know any programming languages I had to do it all from DOS.

Specifically for the programs that didn't run on all drives automatically, I had to get them to detect the mounted drives then run the specified /switches on that drive.

For example:
Code:
IF EXIST C:\Recycler dirms c compact defrag
IF EXIST D:\Recycler dirms d compact defrag
IF EXIST E:\Recycler dirms e compact defrag
Right down to Z:\ maybe not the most efficient way ever but it works!

Luckily for me the Recycler folder exists on all mounted drives, or else I've have to figure something else out.

Maintenance Routine Thread

/edit
I'm still having trouble getting Regcleaner and Ad-ware to detect their installation locations, since they don't store their locations in the registry as a value. I've not figured that out yet.
 

yoyo

_________________
#4
You are aware that this "Recycler" trick won't work on FAT32 volumes? The recycle bin folder is named "Recycled" there.

To parse the registry value for mounted devices you could use this:

Code:
reg query HKLM\system\mounteddevices | find "DosDevices" | find /v /i "5C"  > :DRIVES
for /f "tokens=2 delims=\: " %%a in (:DRIVES) do echo %%a:\ >> test.txt
Replace echo %%a:\ >> test.txt with the command you want to use. The code above passes just the driveletter. So add ":" or ":\" to %%a just as needed.

----------------
Adaware writes its location into the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall.
Problem the name of the subkey is different depending on the version (Ad-aware 6 Personal or Ad-aware 6 Professional - are there others?)
You could use these two commands - one will fail:

Code:
for /f "usebackq skip=4 tokens=3" %%i in (`reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\Ad-aware 6 Personal" /v UninstallString`) do start %%~dpi\Ad-aware.exe
for /f "usebackq skip=4 tokens=3" %%i in (`reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\Ad-aware 6 Professional" /v UninstallString`) do start %%~dpi\Ad-aware.exe
---------

I never use any kind of reg cleaners. So don't know about that.
 
#5
Thats pretty sweet info there, very helpful.

I get everything except the use of "usebackq skip=4 tokens=3" after reading tonnes of documentation this is the only thing that I just don't understand.
 

yoyo

_________________
#6
First an update for the Adaware batch without failing command

Code:
for /f "usebackq delims=" %%a in (`reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall ^| find "Ad-aware"`) do for /f "usebackq skip=4 tokens=3" %%i in (`reg query "%%a" /v UninstallString`) do start %%~dpiAd-aware.exe
Command line options for adaware:
http://www.lavasoftsupport.com/index.php?showtopic=22411
http://www.lavasoftsupport.com/index.php?act=ST&f=14&t=4041


Some links for understanding the for /f stuff. Maybe you know them already. It is mainly a process of trial and error and debugging to get these commands to work. Sometimes it is just the order the delimiters are listed that causes a batch to fail.

http://www.robvanderwoude.com/index.html
http://www.robvanderwoude.com/ntfortokens.html

http://www.ss64.com/nt/for.html

and of course for /? at the command prompt.


.
 

Members online

No members online now.

Latest posts

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,962
Messages
673,240
Members
89,015
Latest member
loxioalix