Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Batch file help. For loop not working...

10 Sep 2014   #1
MeshMode

Windows 7 Professional 64-bit
 
 
Batch file help. For loop not working...

What im trying to accomplish:
-I want to REG QUERY a registry entry that will output the value of a (*SpeedDuplex) string value
-I then want to store that value in a variable

The command im using and the output:
REG QUERY "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0007" /v *SpeedDuplex

Output:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BF
C1-08002BE10318}\0007
*SpeedDuplex REG_SZ 0

End of search: 1 match(es) found.


My batch file looks like this:
@echo off
for /f "skip=2 tokens=3 delims= " %%R in ('REG QUERY "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0007" /v *SpeedDuplex') do (
set "reg_value=%%R"
)
echo %reg_value%


Output of %reg_value%: which if you notice is the third word in the last line?
Search:


Tried changing the skip and tokens with no luck and im racking my brain because it looks correct to me. Anyway if anyone can point me in the right direction I would appreciate it. Thanks in advance and lets play some Destiny


My System SpecsSystem Spec
.
10 Sep 2014   #2
Tookeri

Windows 7 Pro 32
 
 

The problem is that the last output is: End of search: 1 match(es) found.
And the 3rd word there is search:

If you try this instead:

for /f "tokens=3" %%R in ('REG QUERY "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0007" /v *SpeedDuplex ^| find "SpeedDuplex"') do (

The last bold part will filter the output to only the line that displays SpeedDuplex. Then the 3rd word in the last line will be:

*SpeedDuplex REG_SZ 0
My System SpecsSystem Spec
10 Sep 2014   #3
MeshMode

Windows 7 Professional 64-bit
 
 
:D

Quote   Quote: Originally Posted by Tookeri View Post
The problem is that the last output is: End of search: 1 match(es) found.
And the 3rd word there is search:

If you try this instead:

for /f "tokens=3" %%R in ('REG QUERY "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0007" /v *SpeedDuplex ^| find "SpeedDuplex"') do (

The last bold part will filter the output to only the line that displays SpeedDuplex. Then the 3rd word in the last line will be:

*SpeedDuplex REG_SZ 0

That worked! Ill most def save that ^| find trick for the future. Thanks for taking the time to reply. Peace
My System SpecsSystem Spec
.

10 Sep 2014   #4
Tookeri

Windows 7 Pro 32
 
 

You're welcome! And this might be good to know too:

The ^ only works in a for loop. If you run it in a command prompt you have to skip that and only use | find "SpeedDuplex"
My System SpecsSystem Spec
10 Sep 2014   #5
MeshMode

Windows 7 Professional 64-bit
 
 

Quote   Quote: Originally Posted by Tookeri View Post
You're welcome! And this might be good to know too:

The ^ only works in a for loop. If you run it in a command prompt you have to skip that and only use | find "SpeedDuplex"
LOL! I figured that out since its the first thing I tried after it worked in the batch file. Thanks again.
My System SpecsSystem Spec
Reply

 Batch file help. For loop not working...




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
How to run a batch file at logoff & some batch scripting help please
Hiya, I'd just like to run a simple batch file at logoff to backup some settings. I plan to use Robocopy, which is what i use to more thorough backups. Two questions: 1. How make it run by clicking Start > Shutdown? (i realise i could make a shutdown batch file and run it instead, but i'd...
Backup and Restore
Batch file not working as expected
The following batch file displays the txt but immediately erases. Why? @Echo off ECHO There have been 15 minutes or more of inactivity on this computer. Automatic LOGOFF will occur in 60 seconds.
General Discussion
batch file is not working
I created a batch file with rasdial command....if i try to run it a command prompt window opens for a fraction of second and then nothing happens...i tried to run it as admin...still no change.. what do I need to do?
Performance & Maintenance
Batch File that grabs file names from folder to insert into batch file
Ok I'm totally at a loss on how to word this so I'm just going to write it out the best that I can... :confused: First I have a batch file that I'm writing that will convert mp4 files to mp3 files (I have a lot) for a buddies band using ffmpeg. Here's the code that I'm using: ffmpeg -i...
General Discussion
In need of help doing a FOR /F Do loop in a CMD Batch
I am in need of help doing a FOR /F Do loop in a CMD Batch script. I am trying to write a batch script that will ping all IP addresses in a host file except for an IP address that starts with 127 and skip all commented lines in the hostfile or that start with a #. my current code will ping...
General Discussion
Windows xp batch file not working in Windows 7
Hi All, Script below used to work fine with Windows Xp set sqlDB=%2 set sshFile=ssh_%1 ssh dep@stdetails.com "/home/deployment/bin/ssh_dump.sh %1" scp dep@stdetails.com:/home/deployment/workspace/%sshFile%.sql.gz . 7z x %sshFile%.sql.gz
General Discussion


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 13:26.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App