Solved Batch file help. For loop not working...

MeshMode

New member
Local time
10:44 AM
Messages
10
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 Computer

Computer type
PC/Desktop
OS
Windows 7 Professional 64-bit
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 Computer

Computer type
Laptop
Computer Manufacturer/Model Number
HP Elitebook 8540p
OS
Windows 7 Pro 32
CPU
Intel(R) Core(TM) i5 CPU M 540 @ 2.53GHz
Motherboard
Hewlett-Packard 1521
Memory
4,00 GB (Usable 2,98)
Graphics Card(s)
NVIDIA NVS 5100M
Sound Card
NVIDIA High Definition Audio
Screen Resolution
1600x900
Hard Drives
INTEL SSDSA2CW120G3
Antivirus
F-Secure Internet Security
Browser
IE, Firefox, Opera
Other Info
Sandboxie,
SRP (Software Restriction Policy),
EMET (Enhanced Mitigation Experience Toolkit),
WFC (Windows Firewall Control by BiniSoft),
Malwarebytes Premium
:D

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 Computer

Computer type
PC/Desktop
OS
Windows 7 Professional 64-bit
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 Computer

Computer type
Laptop
Computer Manufacturer/Model Number
HP Elitebook 8540p
OS
Windows 7 Pro 32
CPU
Intel(R) Core(TM) i5 CPU M 540 @ 2.53GHz
Motherboard
Hewlett-Packard 1521
Memory
4,00 GB (Usable 2,98)
Graphics Card(s)
NVIDIA NVS 5100M
Sound Card
NVIDIA High Definition Audio
Screen Resolution
1600x900
Hard Drives
INTEL SSDSA2CW120G3
Antivirus
F-Secure Internet Security
Browser
IE, Firefox, Opera
Other Info
Sandboxie,
SRP (Software Restriction Policy),
EMET (Enhanced Mitigation Experience Toolkit),
WFC (Windows Firewall Control by BiniSoft),
Malwarebytes Premium
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 Computer

Computer type
PC/Desktop
OS
Windows 7 Professional 64-bit
Back
Top