C# 为什么安装Windows服务时会记录系统错误7030?
每次在运行Windows 7或Windows Server 2008 R2的系统上安装“我的Windows服务”(在Visual Studio 2010的C#中开发)时,都会记录系统错误7030。该服务未配置为交互式。我创建的自定义子类将帐户类型设置为NetworkService:C# 为什么安装Windows服务时会记录系统错误7030?,c#,windows-services,installation,C#,Windows Services,Installation,每次在运行Windows 7或Windows Server 2008 R2的系统上安装“我的Windows服务”(在Visual Studio 2010的C#中开发)时,都会记录系统错误7030。该服务未配置为交互式。我创建的自定义子类将帐户类型设置为NetworkService: private System.ServiceProcess.ServiceProcessInstaller _serviceProcessInstaller; private System.ServiceProces
private System.ServiceProcess.ServiceProcessInstaller _serviceProcessInstaller;
private System.ServiceProcess.ServiceInstaller _serviceInstaller;
public ProjectInstaller()
{
InitializeComponent();
}
private void InitializeComponent()
{
_serviceProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller();
_serviceInstaller = new System.ServiceProcess.ServiceInstaller();
_serviceProcessInstaller.Account = System.ServiceProcess.ServiceAccount.NetworkService;
_serviceProcessInstaller.Password = null;
_serviceProcessInstaller.Username = null;
_serviceInstaller.ServiceName = Resources.ServiceName;
_serviceInstaller.Description = Resources.ServiceDescription;
_serviceInstaller.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
Installers.AddRange(new Installer[]
{
_serviceProcessInstaller,
_serviceInstaller
});
}
我还尝试将帐户类型设置为LocalSystem,但在本例中也记录了错误7030
在同一安装程序子类中,我还尝试根据以下内容取消设置注册表项:
//
///Override OnCommitted()将Interactive的值覆盖为false。
///
///
///看https://stackoverflow.com/questions/1945529/how-can-i-configure-my-windows-service-in-the-code-to-access-the-desktop
///
///
已提交受保护的覆盖无效(System.Collections.IDictionary savedState)
{
const string pathToKey=@“SYSTEM\CurrentControlSet\services\MyService.exe”;
常量字符串type=“type”;
使用(var registryKey=Registry.LocalMachine.OpenSubKey(pathToKey,true))
{
if(registryKey!=null&®istryKey.GetValue(类型)!=null)
{
SetValue(类型,((int)registryKey.GetValue(类型)&~0x100));
}
}
基础。未提交(保存状态);
}
这两次修复尝试都没有成功。因此,我也看了以下内容:和
/// <summary>
/// Override OnCommitted() to overwrite the value of Interactive to be false.
/// </summary>
/// <remarks>
/// See https://stackoverflow.com/questions/1945529/how-can-i-configure-my-windows-service-in-the-code-to-access-the-desktop
/// </remarks>
/// <param name="savedState"></param>
protected override void OnCommitted(System.Collections.IDictionary savedState)
{
const string pathToKey = @"SYSTEM\CurrentControlSet\services\MyService.exe";
const string type = "Type";
using (var registryKey = Registry.LocalMachine.OpenSubKey(pathToKey, true))
{
if (registryKey != null && registryKey.GetValue(type) != null)
{
registryKey.SetValue(type, (((int)registryKey.GetValue(type) & ~0x100)));
}
}
base.OnCommitted(savedState);
}