Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi
Im Trying to add a registry key using c# in order to my app runs on startup. But windows 7 and windows 8 are changing the path from "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" to
"HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run" and my app doesn't run inmediately.

Used code, below:


C#
RegistryKey rlmkey = Registry.LocalMachine.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
               rlmkey.SetValue("BiosUpdater", BUConfig.CurrentRoot + @"BiosUpdaterPL.exe");
               RegistryKey Aquiles = Registry.LocalMachine.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
               Aquiles.SetValue("Aquiles", BUConfig.CurrentRoot + @"AquilesMonitor.exe");


How Do I Avoid this behavior?
Posted
Updated 2-Sep-14 5:07am
v2

1 solution

It's a shame you're using .NET 3.5 - .NET 4.0 added an API specifically for this purpose:
C#
using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
using (var key = hklm.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"))
{
   key.SetValue("BiosUpdater", BUConfig.CurrentRoot + @"BiosUpdaterPL.exe");
   key.SetValue("Aquiles", BUConfig.CurrentRoot + @"AquilesMonitor.exe");
}

If you can't upgrade to .NET 4.0, then you'll need to P/Invoke the necessary Windows API functions. There's a decent example here:
http://www.rhyous.com/2011/01/24/how-read-the-64-bit-registry-from-a-32-bit-application-or-vice-versa/[^]
 
Share this answer
 
Comments
Witcacy 2-Sep-14 11:42am    
Hi, im using cause my app runs on W7 or XP.
Richard Deeming 2-Sep-14 11:43am    
XP supports .NET 4.0; it's only .NET 4.5 that won't install on XP.
Witcacy 3-Sep-14 9:26am    
well, my app is running in a production line where devices are tested by my app, there is no time for installations, i was running it in 4.5 using metro styles but in w7 my app is crashing. So, I created 2.0 and 3.5 versions, it would be easier. Thanks Richard.

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