Link to home
Start Free TrialLog in
Avatar of procit
procit

asked on

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.
Avatar of hongjun
hongjun
Flag of Singapore image

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

ASKER CERTIFIED SOLUTION
Avatar of guvera
guvera
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of procit
procit

ASKER

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?