Silence reg query within For

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
AznChillin
Posts: 5
Joined: 30 May 2014 06:04

Silence reg query within For

#1 Post by AznChillin » 30 May 2014 06:19

I want to silence reg query that is within a for. if the registry doesn't exist i don't want the error to show.
Here is the line i have

Code: Select all

FOR /F "skip=2 tokens=2,*" %%A IN ('reg.exe query "HKLM\SOFTWARE\Windows" /v "ExePath"') DO set "PATHEXE=%%B"

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Silence reg query within For

#2 Post by foxidrive » 30 May 2014 06:30

Here's something that should work:

Code: Select all

FOR /F "skip=2 tokens=2,*" %%A IN ('reg.exe query "HKLM\SOFTWARE\Windows" /v "ExePath" 2^>nul ') DO set "PATHEXE=%%B"

AznChillin
Posts: 5
Joined: 30 May 2014 06:04

Re: Silence reg query within For

#3 Post by AznChillin » 30 May 2014 06:59

foxidrive wrote:Here's something that should work:

Code: Select all

FOR /F "skip=2 tokens=2,*" %%A IN ('reg.exe query "HKLM\SOFTWARE\Windows" /v "ExePath" 2^>nul ') DO set "PATHEXE=%%B"

Thank you so much. You are awesome.

AznChillin
Posts: 5
Joined: 30 May 2014 06:04

Re: Silence reg query within For

#4 Post by AznChillin » 30 May 2014 07:01

foxidrive wrote:Here's something that should work:

Code: Select all

FOR /F "skip=2 tokens=2,*" %%A IN ('reg.exe query "HKLM\SOFTWARE\Windows" /v "ExePath" 2^>nul ') DO set "PATHEXE=%%B"

Wait... error is still showing on 32 bit systems...

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Silence reg query within For

#5 Post by foxidrive » 30 May 2014 07:52

What is the error message?

AznChillin
Posts: 5
Joined: 30 May 2014 06:04

Re: Silence reg query within For

#6 Post by AznChillin » 30 May 2014 08:31

foxidrive wrote:What is the error message?

I am getting an Error: The system was unable to find the specified registry key or value

AznChillin
Posts: 5
Joined: 30 May 2014 06:04

Re: Silence reg query within For

#7 Post by AznChillin » 30 May 2014 08:34

Nevermind, it works, it didn't replace the file in my virtual machine. Thank you so much for your help.

Post Reply