The source was not found, but some or all event logs could not be searched
Had the same exception. In my case, I had to run Command Prompt with Administrator Rights.
From the Start Menu, right click on Command Prompt, select "Run as administrator".
Launch Developer command line "As an Administrator". This account has full access to Security log
EventLog.SourceExists
enumerates through the subkeys of HKLM\SYSTEM\CurrentControlSet\services\eventlog
to see if it contains a subkey with the specified name. If the user account under which the code is running does not have read access to a subkey that it attempts to access (in your case, the Security
subkey) before finding the target source, you will see an exception like the one you have described.
The usual approach for handling such issues is to register event log sources at installation time (under an administrator account), then assume that they exist at runtime, allowing any resulting exception to be treated as unexpected if a target event log source does not actually exist at runtime.
For me this error was due to the command prompt, which was not running under administrator privileges. You need to right click on the command prompt and say "Run as administrator".
You need administrator role to install or uninstall a service.