Discussion:
.NET Registry.GetValue method returns null when called from ServicedComponent as COM+ app
(too old to reply)
Arturo Martinez
2008-03-27 05:16:45 UTC
Permalink
Raw Message
Does any one knows why everytime I call the .NET Registry.GetValue method
from a servicedcomponent always returns null?

even if the value exists in the Registry.

Is there a setting I need to change in the COM Application to be able to
read the Registry?

Thanks
Jeffrey Tan[MSFT]
2008-03-27 09:07:39 UTC
Permalink
Raw Message
Hi Arturo,

I assume you are using "Server Application" in the COM+ setting
"Activation" tab, yes? This will run your component in a separate hosted
Windows Service. Can you tell me what registry key you are trying to get?
If you are trying to accessing the registry keys under HKEY_CURRENT_USER
hive, you may get this problem.

HKEY_CURRENT_USER registry hive may be different for different processes.
It is determined by the process running account. In "Server application"
activation scenario, you can specify your service running account in the
"Identity" tab in the COM+ setting dialog. If you specify a service account
such as "Local System" or "Local Service", your COM+ service will load the
HKEY_CURRENT_USER hive for "Local System" or "Local Service" account
instead of the interactive user. So when you are accessing
HKEY_CURRENT_USER hive while thinking under interactive user, you will get
surprise(different result).

To resolve this issue, you may change your COM+ service setting to run
under the interactive user account(change it in the dcomcnfg.exe->COM+
Applications->[your COM+ service]->Properties dialog->Identity tab page).
Then your COM+ service will load the same copy of HKEY_CURRENT_USER hive as
all the interactive processes in the GUI desktop.

If you still want to run the COM+ service under a service account and have
the ability to access the interactive account HKEY_CURRENT_USER hive, you
have to parse under the "HKEY_USERS\[interactive user SID]" hive. This
needs a lot more code. Anyway, if you want to take this solution, please
feel free to tell me, I will work with you.

Hope it helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
***@microsoft.com.
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Arturo Martinez
2008-03-27 13:21:33 UTC
Permalink
Raw Message
Jeffrey, thanks for your reply

Yers, I'm using Server Application but the key I'm trying to acces is
HKEY_LOCAL_MACHINE and is running under my Identity (Administrator) just for
testing purposes.
I don't know if I'm missing something in the configuration of the
application.
If I make the same call from another process outside the COM+ app everything
works.

Are there some attributes that I need to add to gain access to the Registry?

Thanks
Post by Jeffrey Tan[MSFT]
Hi Arturo,
I assume you are using "Server Application" in the COM+ setting
"Activation" tab, yes? This will run your component in a separate hosted
Windows Service. Can you tell me what registry key you are trying to get?
If you are trying to accessing the registry keys under HKEY_CURRENT_USER
hive, you may get this problem.
HKEY_CURRENT_USER registry hive may be different for different processes.
It is determined by the process running account. In "Server application"
activation scenario, you can specify your service running account in the
"Identity" tab in the COM+ setting dialog. If you specify a service account
such as "Local System" or "Local Service", your COM+ service will load the
HKEY_CURRENT_USER hive for "Local System" or "Local Service" account
instead of the interactive user. So when you are accessing
HKEY_CURRENT_USER hive while thinking under interactive user, you will get
surprise(different result).
To resolve this issue, you may change your COM+ service setting to run
under the interactive user account(change it in the dcomcnfg.exe->COM+
Applications->[your COM+ service]->Properties dialog->Identity tab page).
Then your COM+ service will load the same copy of HKEY_CURRENT_USER hive as
all the interactive processes in the GUI desktop.
If you still want to run the COM+ service under a service account and have
the ability to access the interactive account HKEY_CURRENT_USER hive, you
have to parse under the "HKEY_USERS\[interactive user SID]" hive. This
needs a lot more code. Anyway, if you want to take this solution, please
feel free to tell me, I will work with you.
Hope it helps.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Jeffrey Tan[MSFT]
2008-03-28 09:22:38 UTC
Permalink
Raw Message
Hi Arturo,

Thanks for your feedback.

Oh, this sounds an unusual situation to me. Does the Registry.GetValue
only returns a null reference? Is there any exception throw in your COM+
application? If this is a permission issue, Registry.GetValue() should
throw SecurityException as documented in MSDN.

Also, does this problem happen to all registry keys under HKLM or several
specific keys? I have created a sample ServicedComponent followed the steps
in the article below(running under the interactive user account):
http://www.15seconds.com/issue/030501.htm

My code looks like this:

'''Server
<Assembly: ApplicationName("MyRegService")>
<Assembly: AssemblyKeyFile("..\..\bin\key.snk")>
<Assembly: ApplicationActivation(ActivationOption.Server)>
Public Class MyRegService
Inherits ServicedComponent

Public Function GetRegValue(ByVal keyName As String, ByVal valueName As
String) As String
Return Registry.GetValue(keyName, valueName, Nothing)
End Function
End Class

'''Client
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim obj As RegistryComponent.MyRegService = New
RegistryComponent.MyRegService()
MsgBox(obj.GetRegValue("HKEY_LOCAL_MACHINE\SYSTEM\Setup",
"SystemPartition"))
End Sub
End Class

I am reading SystemPartition value under HKLM\SYSTEM\Setup key. It works
without any problem. So it seems that I can not reproduce your problem
locally.

To troubleshoot this issue, I would recommend you to use Process Monitor to
monitor the registry activities of your COM+ process. In dcomcnfg.exe, if
your COM+ starts, your application will be listed under the "Running
Processes" node. In it, you will find the your running COM+ process id.
Then, in the ProcMon, you may filter by the process id so that you only
monitor your COM+ application registry activity.(remember to dismiss the
file system button so that ProcMon will not show the file system activity).
Also, you may input add another filter "Path" "Contains"
"HKLM\SYSTEM\Setup" to eliminate the unnecessary output. You may download
ProcMon from the link below:
http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx

I think the ProcMon records may reveal why the registry access fails. You
may paste it here for analysis.

Finally, it would be more efficient if you could provide a sample project
with detailed reproduce steps. Before doing this, you might want to check
if this problem can be reproduced on other machines.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=========================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
***@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
Jeffrey Tan[MSFT]
2008-04-03 02:29:47 UTC
Permalink
Raw Message
Hi Arturo,

How about this issue now? Have you reviewed my last reply to you? Have you
tried to use Process Monitor to monitor the COM+ process registry
activities?

If you still need any help or have any concern please feel free to tell me,
thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=========================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
***@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
Nhoc Hieu
2011-03-15 03:59:20 UTC
Permalink
Raw Message
Hi everyone!

Does anyone interested in this issue?
My issue is a little different. I use a webservice in order to get and return Registry value. For explicit more, example follow:

RegistryKey regKey = Registry.CurrentUser.OpenSubKey("Software\\Yahoo\\Pager");
string sUserName = regKey.GetValue("Yahoo! User ID").ToString();
regKey.Close();

In winform application, i can get 'sUserName' variable easily, but i cann't get it on a webservice.

Can guy help me? Tks so much! ^^
This is a multi-part message in MIME format.
------=_NextPart_000_0012_01C88F9F.D727C920
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Does any one knows why everytime I call the .NET Registry.GetValue =
method=20
from a servicedcomponent always returns null?
even if the value exists in the Registry.
Is there a setting I need to change in the COM Application to be able to =
read the Registry?
Thanks
------=_NextPart_000_0012_01C88F9F.D727C920
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META name=3DGENERATOR content=3D"MSHTML 6.00.6001.17184">
<STYLE></STYLE>
</HEAD><FONT face=3DArial><FONT size=3D2>
<BODY>
<DIV>
<DIV><FONT face=3DCalibri>Does any one knows why everytime I call the =
.NET=20
Registry.GetValue method <BR>from a servicedcomponent always returns=20
null?</FONT></DIV>
<DIV><FONT face=3DCalibri></FONT>&nbsp;</DIV>
<DIV><FONT face=3DCalibri>even if the value exists in the =
Registry.</FONT></DIV>
<DIV><FONT face=3DCalibri></FONT>&nbsp;</DIV>
<DIV><FONT face=3DCalibri>Is there a setting I need to change in the COM =
Application to be able to <BR>read the Registry?</FONT></DIV>
<DIV><FONT face=3DCalibri></FONT>&nbsp;</DIV>
<DIV><FONT =
face=3DCalibri>Thanks</FONT></DIV></DIV></BODY></HTML></FONT></FONT>
------=_NextPart_000_0012_01C88F9F.D727C920--
Post by Jeffrey Tan[MSFT]
Hi Arturo,
I assume you are using "Server Application" in the COM+ setting
"Activation" tab, yes? This will run your component in a separate hosted
Windows Service. Can you tell me what registry key you are trying to get?
If you are trying to accessing the registry keys under HKEY_CURRENT_USER
hive, you may get this problem.
HKEY_CURRENT_USER registry hive may be different for different processes.
It is determined by the process running account. In "Server application"
activation scenario, you can specify your service running account in the
"Identity" tab in the COM+ setting dialog. If you specify a service account
such as "Local System" or "Local Service", your COM+ service will load the
HKEY_CURRENT_USER hive for "Local System" or "Local Service" account
instead of the interactive user. So when you are accessing
HKEY_CURRENT_USER hive while thinking under interactive user, you will get
surprise(different result).
To resolve this issue, you may change your COM+ service setting to run
under the interactive user account(change it in the dcomcnfg.exe->COM+
Applications->[your COM+ service]->Properties dialog->Identity tab page).
Then your COM+ service will load the same copy of HKEY_CURRENT_USER hive as
all the interactive processes in the GUI desktop.
If you still want to run the COM+ service under a service account and have
the ability to access the interactive account HKEY_CURRENT_USER hive, you
have to parse under the "HKEY_USERS\[interactive user SID]" hive. This
needs a lot more code. Anyway, if you want to take this solution, please
feel free to tell me, I will work with you.
Hope it helps.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Post by Arturo Martinez
Jeffrey, thanks for your reply
Yers, I'm using Server Application but the key I'm trying to acces is
HKEY_LOCAL_MACHINE and is running under my Identity (Administrator) just for
testing purposes.
I don't know if I'm missing something in the configuration of the
application.
If I make the same call from another process outside the COM+ app everything
works.
Are there some attributes that I need to add to gain access to the Registry?
Thanks
Post by Jeffrey Tan[MSFT]
Hi Arturo,
Thanks for your feedback.
Oh, this sounds an unusual situation to me. Does the Registry.GetValue
only returns a null reference? Is there any exception throw in your COM+
application? If this is a permission issue, Registry.GetValue() should
throw SecurityException as documented in MSDN.
Also, does this problem happen to all registry keys under HKLM or several
specific keys? I have created a sample ServicedComponent followed the steps
http://www.15seconds.com/issue/030501.htm
'''Server
<Assembly: ApplicationName("MyRegService")>
<Assembly: AssemblyKeyFile("..\..\bin\key.snk")>
<Assembly: ApplicationActivation(ActivationOption.Server)>
Public Class MyRegService
Inherits ServicedComponent
Public Function GetRegValue(ByVal keyName As String, ByVal valueName As
String) As String
Return Registry.GetValue(keyName, valueName, Nothing)
End Function
End Class
'''Client
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim obj As RegistryComponent.MyRegService = New
RegistryComponent.MyRegService()
MsgBox(obj.GetRegValue("HKEY_LOCAL_MACHINE\SYSTEM\Setup",
"SystemPartition"))
End Sub
End Class
I am reading SystemPartition value under HKLM\SYSTEM\Setup key. It works
without any problem. So it seems that I can not reproduce your problem
locally.
To troubleshoot this issue, I would recommend you to use Process Monitor to
monitor the registry activities of your COM+ process. In dcomcnfg.exe, if
your COM+ starts, your application will be listed under the "Running
Processes" node. In it, you will find the your running COM+ process id.
Then, in the ProcMon, you may filter by the process id so that you only
monitor your COM+ application registry activity.(remember to dismiss the
file system button so that ProcMon will not show the file system activity).
Also, you may input add another filter "Path" "Contains"
"HKLM\SYSTEM\Setup" to eliminate the unnecessary output. You may download
http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx
I think the ProcMon records may reveal why the registry access fails. You
may paste it here for analysis.
Finally, it would be more efficient if you could provide a sample project
with detailed reproduce steps. Before doing this, you might want to check
if this problem can be reproduced on other machines.
Hope this helps.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
=========================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
This posting is provided "AS IS" with no warranties, and confers no rights.
Post by Jeffrey Tan[MSFT]
Hi Arturo,
How about this issue now? Have you reviewed my last reply to you? Have you
tried to use Process Monitor to monitor the COM+ process registry
activities?
If you still need any help or have any concern please feel free to tell me,
thanks.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
=========================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
This posting is provided "AS IS" with no warranties, and confers no rights.
Submitted via EggHeadCafe
Pass Values Between Windows Forms
http://www.eggheadcafe.com/tutorials/aspnet/a3e1e170-21d9-4a59-a659-3ead05bb36f2/pass-values-between-windows-forms.aspx
Loading...