Click here to Skip to main content
15,860,972 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hi everyone!

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 can't get it on a webservice, it throws exception: "Object reference not set to an instance of an object"

Experts can help me in this regard?
Thanks so much in advance!
Posted
Updated 16-Mar-11 22:22pm
v4
Comments
Dalek Dave 17-Mar-11 4:22am    
Edited for Grammar and Readability.

It looks like you might be having permission issues.
Have a look here[^].
 
Share this answer
 
Comments
Dalek Dave 17-Mar-11 4:22am    
Good Link
I believe IIS use other account like ASP.NET account.
from your code what I see is the it query on the current user.
so basically the current user will be the ASP.NET account.
RegistryKey regKey = Registry.CurrentUser.OpenSubKey("Software\\Yahoo\\Pager");

will always return null.
try to use the Impersonation feature of ASP.NET.
 
Share this answer
 
v2
Comments
Dalek Dave 17-Mar-11 4:22am    
Sage Advice.
danghieunhoc 19-Apr-11 23:54pm    
Sorry for waiting so long time, i was busy for other project.

I tried the same way as your guide but it failed. I tried all of Windows rights but it still doesn't ok. Could you tell my mistake, pls?
Link follow: 'http://www.mediafire.com/?y55igzyhc5ob7wk'

Tks you very much!
I have tried all ways like: set Full control, set Folder Permissions, set Registry Permissions... etc but i don't successful.
You can see demo project follow: 'http://www.mediafire.com/?y55igzyhc5ob7wk'. I built it by Visual Studio 2005. Debugging-(F5) is ok, but run it as a site through IIS is not successful.

Other any way, please help me, tks!
 
Share this answer
 
v3
How can i make it? Can anyone help me? T_T
 
Share this answer
 
You are trying to access the registry sub-key for the currently logged in user? If so you need to first verify that a user is actually logged in, and then you need to read from the user's specific sub-registry. It could either be via impersonation or via directly specifying the full registry path (CurrentUser will obviously not work). You will also need to deal with permission issues involved in doing this.
 
Share this answer
 
Comments
danghieunhoc 27-Apr-11 4:19am    
I tried setting permissions for IIS, but it didn't get 'sUserName' variable. User logged in or not, not important, bcz i run normally in application environment, but in IIS don't.

Do u tell me more explicit?

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900