Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying a reg key with a space in it

Tags:

batch-file

I am trying to write a batch file that will determine if a PC has a specific MS Hotfix installed, and is running XP SP2, not SP3.

I so far cannot even get the first part of this to work, due to the reg key having a space in "Windows XP"

The batch file so far:

@echo off

reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows XP\SP3\KB932823-v3\>nul
if %errorlevel% EQU 0 goto :nohotfix
if %errorlevel% EQU 1 goto :hotfixpresent


:Hotfixpresent
@echo hot fix is present
pause

:nohotfix
@echo No hotfix is present
pause

the gotos are just placeholders for future code at present.

I get the following error at the moment - Error: Invalid command-line parameters

Anyone got an idea how I can get around this?

thanks,

Rob

like image 403
user2610093 Avatar asked Jul 23 '13 10:07

user2610093


People also ask

Can registry keys have spaces?

You can use a registry key or path that has a space in it (I just did a quick test to confirm it). When you create the name of the attribute in the discovery though, don't include the space. That name is just used within the discovery itself to identify the attribute.

What does Reg_sz mean?

REG_SZ. A null-terminated string. This will be either a Unicode or an ANSI string, depending on whether you use the Unicode or ANSI functions.

How do you check if a registry key exists in a batch file?

How do I check if a key is present in the windows registry. This can be done using reg query key : This command will set %errorlevel% . errorlevel=0 means the key exists.


1 Answers

Use quotes (") around key path.

e.g.

reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows XP\SP3\KB932823-v3">nul
like image 95
anishsane Avatar answered Oct 13 '22 22:10

anishsane