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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15335670/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 16:27:32  来源:igfitidea点击:

Install C# Service on Windows Server (Access Denied)

c#service

提问by Alexander

I created a C# service. Now I want to install that service on Windows Server 2008 R2. I am using the InstallUtilcommand to install the service. I opened the command prompt as an admin.

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

The service should run as a certain user, therefore I set the account to user on the Service Installer.

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

When I run the command I get an error:

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

An exception occured during the Install phase: System.ComponentModel.Win32Exception: Access Denied.

安装阶段发生异常: System.ComponentModel.Win32Exception: Access Denied

Here is the log file:

这是日志文件:

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.

Here is what is displayed on the command prompt:

以下是命令提示符上显示的内容:

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.

Does somebody know what I need to do to install the service?

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

采纳答案by Alexander

I finally could install the service. I was logged into the server in a role called server admin. My Administrator added my account to the local administrators group of the server. After this I could install the service. It seams like the server Admin account, that I used to log into the system did not have full admin priviledges.

我终于可以安装该服务了。我以名为服务器管理员的角色登录到服务器。我的管理员将我的帐户添加到服务器的本地管理员组。在此之后,我可以安装该服务。它就像服务器管理员帐户一样,我用来登录系统的帐户没有完整的管理员权限。

Thanks for your help.

谢谢你的帮助。

回答by David

You really didn't give any details as to what your service does and I am unable to comment direct on your post yet but you might try this link

你真的没有提供任何关于你的服务做什么的细节,我还不能直接对你的帖子发表评论,但你可以试试这个链接

The summary of this is to check and make sure you are running the proper 32/64 bit installutil.exe and to verify your merge module are not causing the issue.

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

Perhaps a better description of your service would help? Does the service install fine on your local machine as opposed to the server?

也许更好地描述您的服务会有所帮助?与服务器相比,该服务是否在您的本地计算机上安装得很好?

回答by radhason power

This Problem is due to Security, Better open Command prompt in RUN AS ADMINISTRATOR and install your Service, it fix your problem surely

这个问题是由于安全性,更好地在 RUN AS ADMINISTRATOR 中打开命令提示符并安装您的服务,它肯定会解决您的问题