Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Value of Registry Key

I have a batch script that checks if a registry key exists and if it does exist then open Internet explorer. What I now want to do is get the value of that registery key and put it in the URL. How can I do this?

@echo off
reg query HKLM\Software\Test\Monitor\Settings
if errorlevel 1 goto not_exist
goto exist

:not_exist

:exist
start "Test" "%ProgramFiles%\Internet Explorer\iexplore.exe" http://localhost:/dashboard.php

Thanks all for any help.

like image 720
Abs Avatar asked Jul 09 '10 14:07

Abs


People also ask

What is a registry key value?

Registry values are name/data pairs stored within keys. Registry values are referenced separately from registry keys. Each registry value stored in a registry key has a unique name whose letter case is not significant.

What is default value of registry key?

What used to be called simply “the value of a registry key” (for since there was only one, there was no need to give it a name) now goes by the special name the default value: It's the value whose name is null. There's nothing particularly special about the default value aside from its unusual name.

How do I get the registry key in PowerShell?

Getting a Single Registry EntryUsing Get-ItemProperty , use the Path parameter to specify the name of the key, and the Name parameter to specify the name of the DevicePath entry. This command returns the standard Windows PowerShell properties as well as the DevicePath property.

How do I browse the registry in PowerShell?

You can browse the registry tree the same way you navigate your drives. HKLM:\ and HKCU:\ are used to access a specific registry hive. Those, you can access the registry key and their parameters using the same PowerShell cmdlets that you use to manage files and folders.


1 Answers

Here you go, should be self explanatory with comments. Let me know if you have any questions.

@echo off

set THEME_REGKEY=HKLM\Software\Microsoft\Windows\CurrentVersion\Themes
set THEME_REGVAL=ThemeName

REM Check for presence of key first.
reg query %THEME_REGKEY% /v %THEME_REGVAL% 2>nul || (echo No theme name present! & exit /b 1)

REM query the value. pipe it through findstr in order to find the matching line that has the value. only grab token 3 and the remainder of the line. %%b is what we are interested in here.
set THEME_NAME=
for /f "tokens=2,*" %%a in ('reg query %THEME_REGKEY% /v %THEME_REGVAL% ^| findstr %THEME_REGVAL%') do (
    set THEME_NAME=%%b
)

REM Possibly no value set
if not defined THEME_NAME (echo No theme name present! & exit /b 1)

REM replace any spaces with +
set THEME_NAME=%THEME_NAME: =+%

REM open up the default browser, searching google for the theme name
start http://www.google.com/search?q=%THEME_NAME%
like image 139
esac Avatar answered Oct 19 '22 19:10

esac