我有一个项目,我已经添加了一个安装程序项目。我跟着这(custom installer)c#应用程序自动启动窗口7
我添加了一个自定义安装程序类。其中一个目的是在任何用户登录时将该程序添加到注册表以进行自动启动。我以管理员身份运行visual studio(在visual studio的顶部说明 - 注意:在计算机管理中,我不是管理员)。我的笔记本电脑也使用了一个名为powerbroker的应用程序。要安装应用程序,请右键单击并选择运行提升。从阅读其他职位运行提升是不一样的管理员,其中可能存在的问题。
无论如何,问题是: 在Visual Studio中,没有错误产生(代码运行正常)添加密钥(我写了一个单独的应用程序来测试这个,但密钥没有被写入 - 我不明白为什么
当我把代码在我的安装程序并运行升高不会引发错误,关键是没有写任何 - 至少,如果它出错了,并回滚安装....
我做尝试为当前用户设置密钥,而且工作正常,但对我无用......
ia也创建了一个本地用户,其中谁是管理员的成员,也没有访问权限。
要总结一下我试图搞清楚的是: 我怎么能扔的注册表写入失败的错误,并回滚安装(记住代码目前不会抛出低于下高架privaleges一个错误,但犯规实际工作)
有没有解决这个问题?
感谢 DAMO
C#安装程序类代码
using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;
using System.Reflection;
using System.IO;
using Microsoft.Win32;
namespace OffLine.Installer
{
// Taken from:http://msdn2.microsoft.com/en-us/library/
// system.configuration.configurationmanager.aspx
// Set 'RunInstaller' attribute to true.
[RunInstaller(true)]
public class InstallerClass : System.Configuration.Install.Installer
{
public InstallerClass()
: base()
{
// Attach the 'Committed' event.
this.Committed += new InstallEventHandler(MyInstaller_Committed);
// Attach the 'Committing' event.
this.Committing += new InstallEventHandler(MyInstaller_Committing);
}
// Event handler for 'Committing' event.
private void MyInstaller_Committing(object sender, InstallEventArgs e)
{
// **** Beta Only **** Set program to autostart
try
{
RegistryKey add = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
add.SetValue("FactoryAuditEventNotification", "\"" + Application.ExecutablePath.ToString() + "\"");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
// Event handler for 'Committed' event.
private void MyInstaller_Committed(object sender, InstallEventArgs e)
{
try
{
Directory.SetCurrentDirectory(Path.GetDirectoryName
(Assembly.GetExecutingAssembly().Location));
Process.Start(Path.GetDirectoryName(
Assembly.GetExecutingAssembly().Location) + "\\FactoryAuditEventNotification.exe");
}
catch
{
// Do nothing...
}
}
// Override the 'Install' method.
public override void Install(IDictionary savedState)
{
base.Install(savedState);
}
// Override the 'Commit' method.
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
}
// Override the 'Rollback' method.
public override void Rollback(IDictionary savedState)
{
base.Rollback(savedState);
}
}
}
查看注册表项HKLM \ .. \ Run的权限。打开注册表。点击键。在编辑菜单上,单击权限。尝试使用[procmon](http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx)来跟踪对hklm \ .. \ run键的访问。 – sergmat
这是编写注册表值的大量代码。你有没有考虑过使用注册表? –
@ christopher painter - 是的,我刚刚尝试过 - 我添加了一个字符串值“[TARGETDIR] myapp.exe”到位置HKPU \ SOFTWARE \ Microsoft \ Windows \ Currentversion \ Run,但这也不起作用 - 它实际上添加此值为HKPU \ SOFTWARE \ WOW6432node \ Microsoft \ Windows \ Currentversion \ Run – user1438082