Thread: Registry Checker

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    17

    Registry Checker

    This boolean always returns false :S
    Anyone have any suggestions as to why?

    Code:
    bool keyExists()
    {
    	HKEY hKey;
    	DWORD lRv = RegOpenKeyEx(HKEY_CURRENT_USER,(LPCTSTR)"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 0, KEY_READ, &hKey);
    	if (lRv == ERROR_SUCCESS)
    		return true;
    	else
    		return false;
    	RegCloseKey(hKey);
    }
    And I'm checking it's return value like so:
    Code:
    if (keyExists())
    	printf("Found");
    else
    	printf("Not Found");

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Reading the documentation, we see this:

    If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.
    Have you tried that?

    And where you've put this
    Code:
    RegCloseKey(hKey);
    it's utterly pointless as you've returned from the function. I'm surprised you don't get at least a warning for unreachable code on that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windows registry helplessly bloats over time?
    By Yarin in forum General Discussions
    Replies: 16
    Last Post: 08-10-2009, 01:52 PM
  2. Registry, Regedit
    By franse in forum C++ Programming
    Replies: 21
    Last Post: 01-29-2009, 09:57 AM
  3. Efficient registry use?
    By bennyandthejets in forum Windows Programming
    Replies: 6
    Last Post: 09-28-2003, 06:28 PM
  4. Registry
    By gvector1 in forum C# Programming
    Replies: 0
    Last Post: 07-30-2003, 04:02 PM
  5. Registry Access
    By ExDigit in forum Windows Programming
    Replies: 3
    Last Post: 01-04-2002, 04:02 AM