How to read registry key value in c# on windows7 64 bit

I have made one com component dll, In that one method returns Registry key value, and one is simple return string.

for e.g.
public string Hello()
        {
            return "Hello from object";
        }
public string IsAgent()
        {
            return Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Test\Agent", "IsAgent", "0").ToString();
        }


Then we have register that dll by making setup & deployment project in vs2010 (framework2.0). Then we are trying to access that method in javascript, for e.g
<html xmlns="http://www.w3.org/1999/xhtml">
<head> <title>ObjectEmbedingTest</title> </head>
<body>
<form method="POST" name="MyForm" id="MyForm">
    <object id="HelloControl" name="HelloControl" border="0"  classid="clsid:9A081BF8-6B1A-4850-B8B1-94AF1282EEC3" >
    </object>
</form>

<script type ="text/javascript">
var objAgentControl = document.forms(0).HelloControl;
alert('objAgentControl=' + objAgentControl.Hello());
alert(objAgentControl.IsAgent());
</script>
</body>
</html>

In this on windows7 32 bit, both methods are working fine, but when we installed it on windows7 64 bit m/c Hello() method working fine but IsAgent() is not working.
procitAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hongjunCommented:
Try this instead
public string IsAgent()
{
    RegistryKey rk = Registry.LocalMachine;
    rk = rk.CreateSubKey(@"SOFTWARE\Test\Agent");
    return rk.GetValue("IsAgent", "0");
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kovilpattiBaluCommented:
hi,

registry key path will be different for Win 7 64 bit..
will be under "Wow6432Node".. your path should be like below..

ie:
(@"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Test\Agent
0
procitAuthor Commented:
Thx.
Yes, I have used Example 2 from this link http://www.rhyous.com/2011/01/24/how-read-the-64-bit-registry-from-a-32-bit-application-or-vice-versa/,
And Now I can access that IsAgent method, but after loading page there is one more message "COM Surrogate has stopped working.", Is it related to this code?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.