如何在启动时添加应用程序以避免在注册表中使用wow6432node [英] How do I Add An application to startup avoiding wow6432node in Registry
问题描述
嗨
我尝试使用c#添加注册表项,以便我的应用程序在启动时运行。但是Windows 7和Windows 8正在改变从 HKLM \ SOFTWARE \ Microoft \ Windows \ CurrentVersion \ Run 到 HKLM的路径\ SOFTWARE \Wow6432Node\Microsoft \ Windows \ CurrentVersion \ Run 我的应用程序不能立即运行。
二手代码,下面:
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:
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?
推荐答案
使用.NET 3.5令人遗憾 - .NET 4.0专门为此添加了一个API:
It's a shame you're using .NET 3.5 - .NET 4.0 added an API specifically for this purpose:
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");
}
如果无法升级到.NET 4.0,则需要P / Invoke必要的Windows API函数。这里有一个不错的例子:
http://www.rhyous.com/2011/01/24/how-read-the-64-bit-registry-from-a-32-bit - 应用 - 反之亦然/ [ ^ ]
这篇关于如何在启动时添加应用程序以避免在注册表中使用wow6432node的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!