Browse Prior Art Database

A Mechanism to Query the Microsoft Windows OS Registry Using a Batch File Disclosure Number: IPCOM000031272D
Original Publication Date: 2004-Sep-20
Included in the Prior Art Database: 2004-Sep-20
Document File: 1 page(s) / 31K

Publishing Venue



Disclosed is a program to read and parse Microsoft Windows registry data from within a batch file (.bat file extension) using only the regedit.exe utility already provided on all installations of Microsoft Windows. This enables batch files to retrieve values such as the default system language and application installation paths without installing or downloading additional software.

This text was extracted from a PDF file.
This is the abbreviated version, containing approximately 98% of the total text.

Page 1 of 1

A Mechanism to Query the Microsoft Windows OS Registry Using a Batch File

First define a subroutine in the batch file:

//subroutine to read registry :getregistrydata set regdata= set key=%1 set value=%2 set file=%3 regedit /E %file%.regedit %key% if not exist %file%.regedit goto :eof type %file%.regedit >%file%.reg del %file%.regedit >nul 2>nul
FOR /f "tokens=1* delims=\=" %%A IN (%file%.reg) DO ( if "{%%~A}" == "{%value%}" set regdata=%%~B

) goto :eof

The subroutine takes 3 parameters:
1) a key defining which segment of the registry is to be examined
2) a particular value defined for this key
3) a temporary file name to be used for processing The subroutine first calls regedit to export the desired segment of the registry into the temporary file. The returned data is unparsable since it is returned in UTF-16 format. The built-in "type" command is then run to convert the output to UTF-8. Finally, the output is parsed using a "FOR /f " command to find the value passed into the subroutine. If found, then an environment value is set containing the value's data, and the subroutine returns to the point just after invocation.

An example invocation: call :getregistrydata
"HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Nls\Language" Default lang set localeID=%regdata%

This example shows how the default system locale can be retrieved by a batch file. The batch file (or any executable invoked after setting this variable) can use this variable to customize the user experien...