PC Review


Reply
Thread Tools Rate Thread

How to check existance of a registry value?

 
 
Jerry
Guest
Posts: n/a
 
      28th Oct 2005
I need to delete a Registry value (not a key). I called RegDeleteValue
expecting it returns ERROR_SUCCESS either if the value gets deleted or
it doesn't exist there at all. However, if the value doesn't exist
there, RegDeleteValue returns an error of "Invalid handle", which may
something failure cases too.

I wonder if there's way to check the existance of a registry value?
Therefore I can call RegDeleteValue only if the value exists there.

In addition, I had thought RegDeleteValue would return something like
"Value doesn't exist". If so, I wouldn't have to check the value's
existance in advance.

Thanks!

 
Reply With Quote
 
 
 
 
Scherbina Vladimir
Guest
Posts: n/a
 
      28th Oct 2005
Hello Jerry.

HKEY hRootKey = NULL;
if( ::RegOpenKeyEx( HKEY_LOCAL_MACHINE, strRegPath,
0, KEY_READ, &hRootKey ) == ERROR_SUCCESS )
{
char strVal[ MAX_PATH ];
DWORD dwLen = sizeof(strVal);
if( ::RegQueryValueEx( hRootKey, "ValueName", NULL,
NULL, reinterpret_cast< BYTE* >( strVal ), &dwLen ) ==
ERROR_SUCCESS )
{
/// value is present, call RegDeleteValue here
}
RegCloseKey(hRootKey);
}

--
[Scherbina Vladimir]

"Jerry" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I need to delete a Registry value (not a key). I called RegDeleteValue
> expecting it returns ERROR_SUCCESS either if the value gets deleted or
> it doesn't exist there at all. However, if the value doesn't exist
> there, RegDeleteValue returns an error of "Invalid handle", which may
> something failure cases too.
>
> I wonder if there's way to check the existance of a registry value?
> Therefore I can call RegDeleteValue only if the value exists there.
>
> In addition, I had thought RegDeleteValue would return something like
> "Value doesn't exist". If so, I wouldn't have to check the value's
> existance in advance.
>
> Thanks!
>



 
Reply With Quote
 
Tom Serface
Guest
Posts: n/a
 
      28th Oct 2005
You could just try to read the value from the registry and see if you get an
error trying to read it. Of course, if you are not an admin user you will
fail unless you have permission for the key with, most likely, a 5 (can't
access) error, but you'll have to watch for that on limited user logins
anyway. This class has a KeyExists() function that might be useful to you
to:

http://www.codeproject.com/system/CRegistry.asp

Tom

"Jerry" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I need to delete a Registry value (not a key). I called RegDeleteValue
> expecting it returns ERROR_SUCCESS either if the value gets deleted or
> it doesn't exist there at all. However, if the value doesn't exist
> there, RegDeleteValue returns an error of "Invalid handle", which may
> something failure cases too.
>
> I wonder if there's way to check the existance of a registry value?
> Therefore I can call RegDeleteValue only if the value exists there.
>
> In addition, I had thought RegDeleteValue would return something like
> "Value doesn't exist". If so, I wouldn't have to check the value's
> existance in advance.
>
> Thanks!
>



 
Reply With Quote
 
sunit
Guest
Posts: n/a
 
      28th Oct 2005

"Jerry" <wrote> I wonder if there's way to check the existance of a registry value?
> Therefore I can call RegDeleteValue only if the value exists there.
>

you can MFC

CRegKey::QueryValue

 
Reply With Quote
 
sunit
Guest
Posts: n/a
 
      28th Oct 2005

"Jerry" < wrote in message
> In addition, I had thought RegDeleteValue would return something like
> "Value doesn't exist". If so, I wouldn't have to check the value's
>


The error return by RegDeleteValue is defined in Winerror.h.
To get a generic description of the error, call FormatMessage with the
FORMAT_MESSAGE_FROM_SYSTEM flag set.
http://msdn.microsoft.com/library/de...us/wcecoreos5/
html/wce50lrfFormatMessage.asp


 
Reply With Quote
 
Jerry
Guest
Posts: n/a
 
      28th Oct 2005
Thanks for everyone's reply! It seems RegQueryValue is the way to go.
But since both RegDeleteValue and RegQueryValue return confusing
errors, why not just use RegDeleteValue with one call instead of using
both functions with two calls?

Thanks!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check for existance of table by name paul.schrum@gmail.com Microsoft Access Form Coding 11 11th Feb 2009 05:06 AM
Check for file existance =?Utf-8?B?Um9u?= Microsoft Access Forms 4 26th Jan 2006 04:41 PM
Check on existance Lodewijk Microsoft Access Forms 2 14th Nov 2004 09:13 PM
Check on existance Lodewijk Microsoft Access Getting Started 2 14th Nov 2004 09:13 PM
Check on existance Lodewijk Microsoft Access Macros 2 14th Nov 2004 09:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:24 AM.