How can I read Key-value pairs from the registry of a remote computer? I have tried using RegConnectRegistry but the subsequent call to RegQueryValueEx gives 'file not found (error no. 2)' error. How can I solve this problem?

Here's the code that I tried:

l_Ret = RegConnectRegistry(CompName, HKEY_LOCAL_MACHINE, &phKey);         
lpValueName  "SYSTEM\\CurrentControlSet\\Services\\EventLog\\System\\NtServicePack\\EventMessageFile";                        
l_Ret = RegQueryValueEx(phKey,lpValueName, NULL, NULL,lpData,  &dSize);

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You are confused a subkey with a value. Run the Registry Editor, the items on the left pane are keys and subkeys while the items on the right pane are values, which have such attributes as name, data and type. So, you need to call RegOpenKeyEx to open the subkey first and then use RegQueryValueEx to retrieve the value.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.