By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,313 Members | 2,725 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,313 IT Pros & Developers. It's quick & easy.

Reading Registry Values in Windows NT Service

P: n/a
Hi!

I am developing an application in C# as a windows NT Service.

This application needs to check for eventlog using
EventLog.Exists("System")

But unfortunately it generates exception "Requested registry access is not
allowed."

After that I tried to verify it using registry
RegistryKey eventLogKey
=Registry.LocalMachine.OpenSubKey("SYSTEM\\Current ControlSet\\Services\\Eventlog\\System");

But it also generate exception.

I check on net but found no solution.

Furthermore if I try to read any registry value under HKEY_CURRENT_USER.

using the above mentioned method it return null.

Any solution to solve this problem will be highly appriciated.

Regards,

Ahmad Jalil Qarshi
Feb 23 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a


"Ahmad Jalil Qarshi" <ah*********@SPAMhotmail.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
| Hi!
|
| I am developing an application in C# as a windows NT Service.
|
| This application needs to check for eventlog using
| EventLog.Exists("System")
|
| But unfortunately it generates exception "Requested registry access is not
| allowed."
|
| After that I tried to verify it using registry
| RegistryKey eventLogKey
|
=Registry.LocalMachine.OpenSubKey("SYSTEM\\Current ControlSet\\Services\\Eventlog\\System");
|
| But it also generate exception.
|
| I check on net but found no solution.
|
| Furthermore if I try to read any registry value under HKEY_CURRENT_USER.
|
| using the above mentioned method it return null.
|
| Any solution to solve this problem will be highly appriciated.
|
| Regards,
|
|
|
| Ahmad Jalil Qarshi
|
|

1. Why do you need to check for the existence of the System log? Your System
is badly broken if this one doesn't exist.
2. HKCU for a service is refering to the User hive of the user account
running the service (if any), not the hive of an interactive user (which
might even not be present).

Willy.
Feb 23 '06 #2

P: n/a
Thanks Willy.

Actually I am making a EventLog Monitor as a service for that I have to
check it out.
Furthermore I have to store some settings in the HKCU, which is a
requirement from the user that's why I need that.

Any Help,

Regards,

Ahmad jalil Qarshi

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:eB**************@TK2MSFTNGP10.phx.gbl...


"Ahmad Jalil Qarshi" <ah*********@SPAMhotmail.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
| Hi!
|
| I am developing an application in C# as a windows NT Service.
|
| This application needs to check for eventlog using
| EventLog.Exists("System")
|
| But unfortunately it generates exception "Requested registry access is
not
| allowed."
|
| After that I tried to verify it using registry
| RegistryKey eventLogKey
|
=Registry.LocalMachine.OpenSubKey("SYSTEM\\Current ControlSet\\Services\\Eventlog\\System");
|
| But it also generate exception.
|
| I check on net but found no solution.
|
| Furthermore if I try to read any registry value under HKEY_CURRENT_USER.
|
| using the above mentioned method it return null.
|
| Any solution to solve this problem will be highly appriciated.
|
| Regards,
|
|
|
| Ahmad Jalil Qarshi
|
|

1. Why do you need to check for the existence of the System log? Your
System
is badly broken if this one doesn't exist.
2. HKCU for a service is refering to the User hive of the user account
running the service (if any), not the hive of an interactive user (which
might even not be present).

Willy.

Feb 23 '06 #3

P: n/a
The "System" eventlog must exist all the time, else your system would not
function. Anyway, if you really need to check this, you need to make sure
that your "service account" (the identity used to run your service) has
appropriate rights to open and read this registry key.
As for your second problem, you need to be aware that a service wich runs
under a specific service account has it's HKCU mapped from:
- HKU\.Default or S-1-5-18 for Local System (SYSTEM) and all other
accounts running the service
- HKU \S-1-5-19 for Local Service
- HKU \ S-1-5-20 for Network Service
So, when a service that runs under "Network User", reads from HKCU, it
effectively reads from HKU\S-11-5-20, not from what you may think - the HKCU
of the interactive logon user! If your service runs under a 'normal' user
account, it's HKCU is mapped from .DEFAULT (or S-1-5-18 which is a mirror
of Default).
That means that the service account needs to have access privileges to the
HKU hive and it's subkeys, this is not a problem for the service accounts,
they are granted full control to their respectively hives, but a 'normal'
account (except an administrator) only has read privileges to the .DEFAULT
hive.

Willy.
"Ahmad Jalil Qarshi" <ah*********@SPAMhotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
| Thanks Willy.
|
| Actually I am making a EventLog Monitor as a service for that I have to
| check it out.
| Furthermore I have to store some settings in the HKCU, which is a
| requirement from the user that's why I need that.
|
| Any Help,
|
| Regards,
|
| Ahmad jalil Qarshi
|
| "Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
| news:eB**************@TK2MSFTNGP10.phx.gbl...
| >
| >
| > "Ahmad Jalil Qarshi" <ah*********@SPAMhotmail.com> wrote in message
| > news:%2***************@TK2MSFTNGP11.phx.gbl...
| > | Hi!
| > |
| > | I am developing an application in C# as a windows NT Service.
| > |
| > | This application needs to check for eventlog using
| > | EventLog.Exists("System")
| > |
| > | But unfortunately it generates exception "Requested registry access is
| > not
| > | allowed."
| > |
| > | After that I tried to verify it using registry
| > | RegistryKey eventLogKey
| > |
| >
=Registry.LocalMachine.OpenSubKey("SYSTEM\\Current ControlSet\\Services\\Eventlog\\System");
| > |
| > | But it also generate exception.
| > |
| > | I check on net but found no solution.
| > |
| > | Furthermore if I try to read any registry value under
HKEY_CURRENT_USER.
| > |
| > | using the above mentioned method it return null.
| > |
| > | Any solution to solve this problem will be highly appriciated.
| > |
| > | Regards,
| > |
| > |
| > |
| > | Ahmad Jalil Qarshi
| > |
| > |
| >
| > 1. Why do you need to check for the existence of the System log? Your
| > System
| > is badly broken if this one doesn't exist.
| > 2. HKCU for a service is refering to the User hive of the user account
| > running the service (if any), not the hive of an interactive user (which
| > might even not be present).
| >
| > Willy.
| >
| >
|
|
Feb 23 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.