Querying a registery Key to check for its existence

S

Simon Osborn

Hi,

In WinXP I can do this,

reg query "hklm\software\microsoft\.netframework" /s
if %errorlevel%==1 (call dotnetfx.exe)
call myprog.exe

However, in Win2000 and I presume in earlier windows platforms, the "reg"
command does not exist. Does anyone out there know how I can check if a
particular registry key exists (In all windows platforms!)?

Your help would be much appreciated!

Simon.
 
R

Ray at

If you want to use only native W2K tools, you can use regedit to export a
..reg file to check. If the key doesn't exist, no file will be exported.

del /q C:\testfile.reg
regedit /a C:\testfile.reg
"HKEY_LOCAL_MACHINE\software\microsoft\.netframework"
IF EXIST C:\testfile.reg (
rem your stuff here
)


I believe that there's a reg.exe in the Resource Kit that you could use if
you have that, though, which would be a bit more reliable.

Ray at work
 
R

Ray at

I don't think it'd work on a Commodore 64.

AFAIK, it'll work on NT4, 5, and 5.1. Test and see.

Ray at work
 
S

Simon Osborn

I'm pretty sure it wouldn't work on a commodore 64, agreed.

The platforms I'm interested in are win95,98,NT,ME,2000,XP...

Is it safe for me to ship the reg.exe file with my cd and use it from there?

Thanks,

Simon.
 
R

Ray at

I can't answer with any certainty. This is often the point at which you
start TESTING in your environment to find the answer instead of relying on a
stranger in a newsgroup! (No offense meant!)

Ray at work
 
M

Major Ninth

with win2k the reg.exe file is actually in the support tools directory on
the 2k install cd, not part of the resource kit

-john
 
T

Torgeir Bakken (MVP)

Simon said:
In WinXP I can do this,

reg query "hklm\software\microsoft\.netframework" /s
if %errorlevel%==1 (call dotnetfx.exe)
call myprog.exe

Hi

Note that testing for the key hklm\software\microsoft\.netframework is not a
sure way to test for the .Net framework. If I uninstall the framework, this key
is still present in registry in some cases.

It is safer and easier to test for files that will not be left if you do a
uninstall of the framework, here is what I test for (should be OS independent
as well I think):

..Net framework v1.1
%windir%\Microsoft.NET\Framework\v1.1.4322\mscorlib.dll

..Net framework v1.0
%windir%\Microsoft.NET\Framework\v1.0.3705\mscorlib.dll

(note that both files can exist at the same time, because .Net supports
side-by-side installations)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top