Installutil with Windows Service 安装,然后立即卸载自定义 Windows 服务

本文关键字:Windows 卸载 自定义 服务 with Service 安装 Installutil 然后 | 更新日期: 2023-09-27 18:32:52

我有一个用c#编写的自定义Windows服务,我需要安装和调试。当我使用

installutil "[path].exe"

从命令行,然后尝试搜索该服务,它不会出现在任何地方的已安装服务列表中。查看安装日志文件,我看到以下内容:

Installing assembly 'myservice'.   
Affected parameters are:  
   logtoconsole =    
   assemblypath = mypath  
   logfile = mylogfile  
Installing service MyService  
Service MyService has been successfully installed.  
Creating EventLog source MyService in log Application...  
Committing assembly 'myservice'.  
Affected parameters are:  
   logtoconsole =   
   assemblypath = myservice  
   logfile = pathtoinstalllog  
Uninstalling assembly myservice  
Affected parameters are:  
   logtoconsole =   
   assemblypath = myservice   
   logfile = pathtoinstalllog  
Removing EventLog source myservice.  
Service myservice is being removed from the system...  
Service myservice was successfully removed from the system.  
Uninstalling assembly myservice'.  
Affected parameters are:    
   logtoconsole =   
   assemblypath = myservice  
   logfile = pathtoinstalllog  
Removing EventLog source myservice.  
Service myservice is being removed from the system...  
Service myservice was successfully removed from the system.

(名称path,myservice,pathtoinstalllog等代替公司细节)

无论如何,从日志文件来看,该服务似乎正在安装,然后立即卸载......

如果需要更多代码或信息,请告诉我,并提前表示感谢。

Installutil with Windows Service 安装,然后立即卸载自定义 Windows 服务

根据我们的讨论总结一下...

  • 使用"InstallUtil full-path"到服务主输出(bin/debug/assembly.exe)。通常,如果出现错误 InstallUtil "执行回滚"(因此请注意错误) - 看起来它正在这样做,但您的日志没有说 - 所以我猜你的"myservice"是错误的路径(也选择正确的 InstallUtil 版本、.NET 框架和 32/64)...

  • 对于安全/帐户问题 - run InstallUtil elevated("以管理员身份运行",命令提示符等) - (如果需要,请尝试为服务帐户指定不同的用户/类型,检查安装程序类详细信息、RunInstaller 属性等)。

希望这有帮助