在Windows Server上安装C#服务(访问被拒绝)

在Windows Server上安装C#服务(访问被拒绝),c#,service,C#,Service,我创建了一个C#服务。现在我想在WindowsServer2008R2上安装该服务。 我正在使用InstallUtil命令安装服务。我以管理员的身份打开了命令提示符 服务应该以某个用户的身份运行,因此我在服务安装程序中将帐户设置为user 当我运行命令时,我得到一个错误: 安装阶段发生异常: System.ComponentModel.win32异常:访问被拒绝 以下是日志文件: Installing assembly 'C:\Service\MyService.exe'. Affected p

我创建了一个C#服务。现在我想在WindowsServer2008R2上安装该服务。 我正在使用InstallUtil命令安装服务。我以管理员的身份打开了命令提示符

服务应该以某个用户的身份运行,因此我在服务安装程序中将帐户设置为user

当我运行命令时,我得到一个错误:

安装阶段发生异常:
System.ComponentModel.win32异常:访问被拒绝

以下是日志文件:

Installing assembly 'C:\Service\MyService.exe'.
Affected parameters are:
   logtoconsole = 
   logfile = C:\Service\MyService.InstallLog
   assemblypath = C:\Service\MyService.exe
Rolling back assembly 'C:\Service\MyService.exe'.
Affected parameters are:
   logtoconsole = 
   logfile = C:\Service\MyService.InstallLog
   assemblypath = C:\Service\MyService.exe
An exception occurred during the Rollback phase of the System.ServiceProcess.ServiceProcessInstaller installer.
System.NullReferenceException: Object reference not set to an instance of an object.
An exception occurred during the Rollback phase of the installation. This exception will be     ignored and the rollback will continue. However, the machine might not fully revert to its initial state after the rollback is complete.
以下是命令提示符上显示的内容:

Beginning the Install phase of the installation.
See the contents of the log file for the C:\Service\MyService.exe assembly's progress.
The file is located at C:\Service\MyService.InstallLog.
Installing assembly 'C:\Service\MyService.exe'.
Affected parameters are:
   logtoconsole =
   logfile = C:\Service\MyService.InstallLog
   assemblypath = C:\Service\MyService.exe

An exception occurred during the Install phase.
System.ComponentModel.Win32Exception: Access Denied
   at System.ServiceProcess.ServiceProcessInstaller.OpenSecurityPolicy()
   at System.ServiceProcess.ServiceProcessInstaller.Install(IDictionary stateSaver)
   at System.Configuration.Install.Installer.Install(IDictionary stateSaver)
   at System.Configuration.Install.Installer.Install(IDictionary stateSaver)
   at System.Configuration.Install.AssemblyInstaller.Install(IDictionary savedState)
   at System.Configuration.Install.Installer.Install(IDictionary stateSaver)
   at System.Configuration.Install.TransactedInstaller.Install(IDictionary savedState)

The Rollback phase of the installation is beginning.
See the contents of the log file for the C:\Service\MyService.exe assembly's progress.
The file is located at C:\Service\MyService.InstallLog.
Rolling back assembly 'C:\Service\MyService.exe'.
Affected parameters are:
   logtoconsole =
   logfile = C:\Service\MyService.InstallLog
   assemblypath = C:\Service\MyService.exe
An exception occurred during the Rollback phase of the System.ServiceProcess.Ser
viceProcessInstaller installer.
System.NullReferenceException: Object reference not set to an instance of an obj
ect.
An exception occurred during the Rollback phase of the installation. This exception will be ignored and the rollback will continue. However, the machine might not fully revert to its initial state after the rollback is complete.

The Rollback phase completed successfully.

The transacted install has completed.
The installation failed, and the rollback has been performed.

有人知道我需要做什么来安装该服务吗?

你确实没有提供任何关于你的服务的细节,我还无法直接在你的帖子上发表评论,但你可以试试

此操作的摘要是检查并确保您正在运行正确的32/64位installutil.exe,并验证合并模块没有导致问题


也许更好地描述一下你的服务会有所帮助?与服务器相比,该服务在本地计算机上安装得好吗?

我终于可以安装该服务了。我以服务器管理员的身份登录到服务器。我的管理员已将我的帐户添加到服务器的本地管理员组。在此之后,我可以安装服务。它和我用来登录系统的服务器管理员帐户一样,没有完全的管理员权限


感谢您的帮助。

此问题是由于安全原因造成的,最好在“以管理员身份运行”中打开命令提示符并安装您的服务,它肯定能解决您的问题

isntaller中是否有自定义代码?安装程序中没有自定义代码。我现在在Visual Studio中创建了一个新的空服务项目,并尝试在服务器上安装该服务。我遇到了相同的错误。您是否使用提升的权限启动命令提示符?右键单击
以管理员身份运行
选项。是的,我以提升的权限打开了命令提示符。