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

问题描述 投票:0回答:4

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

该服务应该以特定用户身份运行,因此我在服务安装程序上将帐户设置为用户。

当我运行命令时,出现错误:

Install阶段出现异常:

System.ComponentModel.Win32Exception: Access Denied

这是日志文件:

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.

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

c# service
4个回答
9
投票

我终于可以安装该服务了。我以服务器管理员的角色登录到服务器。我的管理员将我的帐户添加到服务器的本地管理员组中。之后我就可以安装该服务了。看起来就像我用来登录系统的服务器管理员帐户没有完全的管理员权限。

感谢您的帮助。


2
投票

您确实没有提供有关您的服务的任何详细信息,我还无法直接对您的帖子发表评论,但您可以尝试此链接

总结是检查并确保您正在运行正确的 32/64 位 installutil.exe 并验证您的合并模块不会导致问题。

也许更好地描述您的服务会有帮助?该服务在您的本地计算机(而不是服务器)上安装得很好吗?


1
投票

这个问题是由于安全问题,最好在以管理员身份运行中打开命令提示符并安装您的服务,它肯定可以解决您的问题


0
投票

基本上分两步解决:

  1. 首先,将项目文件的

    DEBUG
    文件夹(这将在
    /bin
    中可用)复制/粘贴到其他文件夹(例如,
    D:\Debug

  2. 在 CMD 提示符下运行以下命令:

    cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
    
  3. 最后,使用以下命令创建服务:

    sc create "ServiceName" binpath="D:\P1\Debug\ServiceName.exe"
    
© www.soinside.com 2019 - 2024. All rights reserved.