Click here to Skip to main content
14,639,066 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have a program written in C++ (not .Net) that is compiled 64bit and has admin rights in the manifest.

I am trying to add the registry settings for the application Event Source but it keeps giving me errors. The key is under LocalMachine:
SYSTEM\CurrentControlSet\Services\EventLog\Application\myappname


My program is a service and has no problems accessing registry values under it's own key under
SYSTEM\CurrentControlSet\Services
.

What I have tried:

I tried using Registry functions and it fails. I have a .reg file that I can double click on and that works. The program is a service so in the install function I want to add the event source and in the uninstall function I want to delete the event source but neither work.
Posted
Updated 17-Jan-18 9:56am
Rate this:
Please Sign up or sign in to vote.

Solution 1

Quote:
it keeps giving me errors
and
Quote:
it fails
are not satisfactory descriptions of the problem.

If you take the trouble to define what you mean by that then you may identify the reason yourself. If you don't describe the problem better than that don't expect a better answer than this.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

The application does NOT get admin rights from the manifest file. It always gets its rights from the account that launched it. If it's a service, the Log On tab of the service properties page shows the account that the service is launched as.

Also, code cannot give itself greater permissions than is already given by the account that launched it. If a normal user account launches your app, that's the MAXIMUM level of permissions the code will ever have. It cannot grant itself an administrator level permission over that.

As was already said, your problem description isn't. We need to know the exact error numbers and messages, as well as the lines of code that caused them, in order to help, otherwise, everything is just guess work.
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

I have it figured out.

If the key doesn't exist, I have to create it. For the delete key, you have to open the key one level above.
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

Running the command prompt as administrator isn't helping. The following gives the error message: The system cannot find the file specified.

dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegKey, 0, KEY_SET_VALUE, &hRegKey);
if ( dwResult == ERROR_SUCCESS ) {
   OutputDebugString(_T("RegOpenKeyEx worked"));
   RegCloseKey(hRegKey);
} else {
   FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL,
            dwResult, LANG_NEUTRAL, szErrText, sizeof(szErrText), NULL);
   OutputDebugString(_T("RegOpenKeyEx failed"));
   OutputDebugString(szErrText);
   return FALSE;
}
   
Comments
Roland M Smith 17-Jan-18 14:50pm
   
The program is not actually running as a service, this is part of it's install function which is triggered by running it with a command argument.
Richard Deeming 17-Jan-18 15:24pm
   
If you want to update your question, click the green "Improve Question" link and edit your question.

If you want to reply to a solution, click the "Have a Question or Comment?" button under that solution.

DO NOT post your update or comment as a new "solution".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100