【问题标题】:Installing Windows Service on a specific computer fails?在特定计算机上安装 Windows 服务失败?
【发布时间】:2013-10-01 10:00:16
【问题描述】:

我有一个安装了以下代码(bat 文件)的 Windows 服务:

@ECHO OFF

REM The following directory is for .NET 4.0
set DOTNETFX2=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319
set PATH=%PATH%;%DOTNETFX2%

echo Installing IEPPAMS Win Service...
echo ---------------------------------------------------
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil "%~dp0MyApp5.WindowsService.exe"
echo ---------------------------------------------------
pause
echo Done.

这适用于几乎所有运行 Windows Server 的计算机。有时必须将 bat 文件重新保存为 ANSI 或 UTF8,但之后它在大多数情况下都可以工作。

但是,我遇到了一台 Windows Server 2012 计算机,在使用 install.but 文件时出现以下异常:

Installing IEPPAMS Win Service...
---------------------------------------------------
Microsoft (R) .NET Framework Installation utility Version 4.0.30319.18010
Copyright (C) Microsoft Corporation.  All rights reserved.


Running a transacted installation.

Beginning the Install phase of the installation.
See the contents of the log file for the C:\MyAppService54\MyApp5.WindowsService
.exe assembly's progress.
The file is located at C:\MyAppService54\MyApp5.WindowsService.InstallLog.
Installing assembly 'C:\MyAppService54\MyApp5.WindowsService.exe'.
Affected parameters are:
   logtoconsole =
   assemblypath = C:\MyAppService54\MyApp5.WindowsService.exe
   logfile = C:\MyAppService54\MyApp5.WindowsService.InstallLog
Unable to create an instance of the MyApp5.WindowsService.ProjectInstaller insta
ller type.
System.Reflection.TargetInvocationException: Exception has been thrown by the ta
rget of an invocation.
The inner exception System.NullReferenceException was thrown with the following
error message: Object reference not set to an instance of an object..

An exception occurred during the Install phase.
System.InvalidOperationException: Unable to create an instance of the MyApp5.Win
dowsService.ProjectInstaller installer type.
The inner exception System.Reflection.TargetInvocationException was thrown with
the following error message: Exception has been thrown by the target of an invoc
ation..
The inner exception System.NullReferenceException was thrown with the following
error message: Object reference not set to an instance of an object..

The Rollback phase of the installation is beginning.
See the contents of the log file for the C:\MyAppService54\MyApp5.WindowsService
.exe assembly's progress.
The file is located at C:\MyAppService54\MyApp5.WindowsService.InstallLog.
Rolling back assembly 'C:\MyAppService54\MyApp5.WindowsService.exe'.
Affected parameters are:
   logtoconsole =
   assemblypath = C:\MyAppService54\MyApp5.WindowsService.exe
   logfile = C:\MyAppService54\MyApp5.WindowsService.InstallLog
Unable to create an instance of the MyApp5.WindowsService.ProjectInstaller insta
ller type.
System.Reflection.TargetInvocationException: Exception has been thrown by the ta
rget of an invocation.
The inner exception System.NullReferenceException was thrown with the following
error message: Object reference not set to an instance of an object..
An exception occurred during the Rollback phase of the System.Configuration.Inst
all.AssemblyInstaller installer.
System.InvalidOperationException: Unable to create an instance of the MyApp5.Win
dowsService.ProjectInstaller installer type.
The inner exception System.Reflection.TargetInvocationException was thrown with
the following error message: Exception has been thrown by the target of an invoc
ation..
The inner exception System.NullReferenceException was thrown with the following
error message: Object reference not set to an instance of an object..
An exception occurred during the Rollback phase of the installation. This except
ion will be ignored and the rollback will continue. However, the machine might n
ot 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.
---------------------------------------------------
Press any key to continue . . .

我看到它得到一个 NullRef 异常,但我没有得到这个?它在所有其他计算机上运行良好。我知道这个特定的环境有一些额外的安全规则,会是这样吗?

【问题讨论】:

  • 这很可能是由于“额外的安全规则”。尝试使用进程监视器查看是否存在失败的底层文件系统操作。

标签: .net windows batch-file windows-services


【解决方案1】:

通过启用资源管理器中的所有安全设置并重新下载它可以工作。我不确定资源管理器如何能够基于安全性更改 zip 文件的内容。我知道阻止/解除阻止问题,但不是这样。

【讨论】:

    【解决方案2】:

    从命令提示符试试这个:

    >sc create "servicenameABC" binPath="path to your service location"
    

    现在转到 services.msc,您可以在那里找到您的服务(servicenameABC), 希望对你有帮助..

    【讨论】:

      猜你喜欢
      • 2011-02-12
      • 2015-08-26
      • 2011-03-10
      • 2011-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-26
      • 2014-06-14
      相关资源
      最近更新 更多