Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 39055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:48:17+00:00 2026-05-10T14:48:17+00:00

Given the key for some registry value (e.g. HKEY_LOCAL_MACHINE\blah\blah\blah\foo) how can I: Safely determine

  • 0

Given the key for some registry value (e.g. HKEY_LOCAL_MACHINE\blah\blah\blah\foo) how can I:

  1. Safely determine that such a key exists.
  2. Programmatically (i.e. with code) get its value.

I have absolutely no intention of writing anything back to the registry (for the duration of my career if I can help it). So we can skip the lecture about every molecule in my body exploding at the speed of light if I write to the registry incorrectly.

Prefer answers in C++, but mostly just need to know what the special Windows API incantation to get at the value is.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T14:48:18+00:00Added an answer on May 10, 2026 at 2:48 pm

    Here is some pseudo-code to retrieve the following:

    1. If a registry key exists
    2. What the default value is for that registry key
    3. What a string value is
    4. What a DWORD value is

    Example code:

    Include the library dependency: Advapi32.lib

    HKEY hKey; LONG lRes = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L'SOFTWARE\\Perl', 0, KEY_READ, &hKey); bool bExistsAndSuccess (lRes == ERROR_SUCCESS); bool bDoesNotExistsSpecifically (lRes == ERROR_FILE_NOT_FOUND); std::wstring strValueOfBinDir; std::wstring strKeyDefaultValue; GetStringRegKey(hKey, L'BinDir', strValueOfBinDir, L'bad'); GetStringRegKey(hKey, L'', strKeyDefaultValue, L'bad');  LONG GetDWORDRegKey(HKEY hKey, const std::wstring &strValueName, DWORD &nValue, DWORD nDefaultValue) {     nValue = nDefaultValue;     DWORD dwBufferSize(sizeof(DWORD));     DWORD nResult(0);     LONG nError = ::RegQueryValueExW(hKey,         strValueName.c_str(),         0,         NULL,         reinterpret_cast<LPBYTE>(&nResult),         &dwBufferSize);     if (ERROR_SUCCESS == nError)     {         nValue = nResult;     }     return nError; }   LONG GetBoolRegKey(HKEY hKey, const std::wstring &strValueName, bool &bValue, bool bDefaultValue) {     DWORD nDefValue((bDefaultValue) ? 1 : 0);     DWORD nResult(nDefValue);     LONG nError = GetDWORDRegKey(hKey, strValueName.c_str(), nResult, nDefValue);     if (ERROR_SUCCESS == nError)     {         bValue = (nResult != 0) ? true : false;     }     return nError; }   LONG GetStringRegKey(HKEY hKey, const std::wstring &strValueName, std::wstring &strValue, const std::wstring &strDefaultValue) {     strValue = strDefaultValue;     WCHAR szBuffer[512];     DWORD dwBufferSize = sizeof(szBuffer);     ULONG nError;     nError = RegQueryValueExW(hKey, strValueName.c_str(), 0, NULL, (LPBYTE)szBuffer, &dwBufferSize);     if (ERROR_SUCCESS == nError)     {         strValue = szBuffer;     }     return nError; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to determine whether or not a given registry key is redirected?
Is there an easy way to verify that a given private key matches a
How do I sort a list of dictionaries by a specific key's value? Given:
Given the schema PERSON { name, spouse } where PERSON.spouse is a foreign key
Given a select with multiple option's in jQuery. $select = $(<select></select>); $select.append(<option>Jason</option>) //Key =
Can somebody please give me an example of a unidirectional @OneToOne primary-key mapping in
Given a specific DateTime value, how do I display relative time, like: 2 hours
Given this XML ... <ListBucketResult xmlns=http://s3.amazonaws.com/doc/2006-03-01/> <Name>public.rpmware.com</Name> <Prefix></Prefix> <Marker></Marker> <MaxKeys>1000</MaxKeys> <IsTruncated>false</IsTruncated> <Contents> <Key>0.dir</Key> <LastModified>2008-06-25T16:09:49.000Z</LastModified>
i give users special URL with access key in it. users accessing the public
The code below gives an error: Property 'Int32 Key' is not defined for type

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.