在 Windows 7 上安装 C# Windows 服务

发布于 2024-09-16 22:27:15 字数 1380 浏览 2 评论 0原文

我有一个批处理文件,我已经用它来安装我的 C# Windows 服务一段时间了,直到 Windows 7 才出现问题。我尝试以管理员权限运行该批处理文件。我尝试使用管理员权限运行命令提示符,导航到 Windows 服务 EXE 并在那里运行 InstallUtil。还是不行。

在阅读了一些其他建议后,我尝试将文件移出 /bin 文件夹并从另一个位置运行它们,但这也不起作用。

批处理文件如下所示

@ECHO OFF

REM The following directory is for .NET 2.0
set DOTNETFX2=%SystemRoot%\Microsoft.NET\Framework\v2.0.50727
set PATH=%PATH%;%DOTNETFX2%

echo Installing IEPPAMS Win Service...
echo ---------------------------------------------------
InstallUtil /i IEPPAMS_WinService1.exe
echo ---------------------------------------------------
echo Done.

,我有一个安装日志文件,我将信息转储到其中。如果我双击 .bat 文件,我会得到

运行事务安装。

开始安装阶段 安装。查看内容 的日志文件 C:\Users\Justin\Desktop\service 测试\IEPPAMS_WinService1.exe 大会的进展。该文件是 位于 C:\Users\Justin\Desktop\service 测试\IEPPAMS_WinService1.InstallLog。

执行过程中发生异常 安装阶段。 系统.InvalidOperationException: 无法打开服务控制管理器 电脑 '。'。这个操作可能会 需要其他特权。内在 例外 System.ComponentModel.Win32Exception 抛出以下错误 消息:访问被拒绝。

安装的回滚阶段 正在开始。查看内容 的日志文件 C:\Users\Justin\Desktop\service 测试\IEPPAMS_WinService1.exe 大会的进展。该文件是 位于 C:\Users\Justin\Desktop\service 测试\IEPPAMS_WinService1.InstallLog。

回滚阶段已完成 成功。

事务安装已完成。

当我以管理员权限运行 .bat 文件时,日志文件中没有写入任何内容,并且该服务仍未安装。

有什么想法吗?在 Windows 7 中安装服务有新方法吗?

I have a batch file that I have been using to install my C# Windows Services for awhile now, never had a problem until Windows 7. I have attempted to run the batch file with Administrator privileges. I have attempted to run the command prompt with admin privs, navigate to the windows service EXE and run InstallUtil there. Still doesn't work.

After reading some other suggestions I tried moving my files out of the /bin folder and running them from another location but that also didn't work.

The batch file looks like this

@ECHO OFF

REM The following directory is for .NET 2.0
set DOTNETFX2=%SystemRoot%\Microsoft.NET\Framework\v2.0.50727
set PATH=%PATH%;%DOTNETFX2%

echo Installing IEPPAMS Win Service...
echo ---------------------------------------------------
InstallUtil /i IEPPAMS_WinService1.exe
echo ---------------------------------------------------
echo Done.

and I have a install log file that I dump info to. If I just double click the .bat file I get

Running a transacted installation.

Beginning the Install phase of the
installation. See the contents of the
log file for the
C:\Users\Justin\Desktop\service
test\IEPPAMS_WinService1.exe
assembly's progress. The file is
located at
C:\Users\Justin\Desktop\service
test\IEPPAMS_WinService1.InstallLog.

An exception occurred during the
Install phase.
System.InvalidOperationException:
Cannot open Service Control Manager on
computer '.'. This operation might
require other privileges. The inner
exception
System.ComponentModel.Win32Exception
was thrown with the following error
message: Access is denied.

The Rollback phase of the installation
is beginning. See the contents of the
log file for the
C:\Users\Justin\Desktop\service
test\IEPPAMS_WinService1.exe
assembly's progress. The file is
located at
C:\Users\Justin\Desktop\service
test\IEPPAMS_WinService1.InstallLog.

The Rollback phase completed
successfully.

The transacted install has completed.

When I run the .bat file with admin privileges nothing is written to the log file, and the service is still not installed.

Any thoughts? Is there a new way to install services in Windows 7?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

数理化全能战士 2024-09-23 22:27:15

右键单击批处理文件并以管理员身份运行它。

您很可能会遇到来自 Windows Vista 和 Windows 7 的新安全模型(用户帐户控制)。即使您以具有管理员权限的帐户运行,您仍然需要提升权限才能执行一些(大多数)管理活动。 (是的,可以禁用此功能,但不要这样做)

编辑... 正确的命令行是 InstallUtil YourApp.exe/i 看起来不是 InstallUtil 的有效开关。

Right click on the batch file and run it as Administrator.

You are most likely running into battle with the new security model (User Account Control) from Windows Vista and Windows 7. Even if you are running as an account that has Admin rights you will still need to elevate to do some (most) administrative activities. (Yes it is possible to disable this feature, but don't)

Edit... The correct commandline is InstallUtil YourApp.exe. The /i does not look to be a vaild switch for InstallUtil.

薄情伤 2024-09-23 22:27:15

因此,我可以通过在命令行中输入 InstallUtil 的整个路径来解决问题,并且它有效。因此,在导航到包含 EXE 的文件夹后,我输入了以下内容:

C:\Windows\Microsoft.NET\Framework\v4.0.21006\installutil.exe
IEPPAMS_WinService1.exe

不知道为什么我现在必须在 Windows 7 中执行此操作,而我在 XP 中从来不需要这样做,但是哦,好吧。感谢您的所有建议!

So I was able to fix the problem by typing in the command line the entire path to InstallUtil and it worked. So after navigating to the folder that had my EXE I typed the following:

C:\Windows\Microsoft.NET\Framework\v4.0.21006\installutil.exe
IEPPAMS_WinService1.exe

Not sure why I have to do that in Windows 7 now when I never had to in XP, but oh well. Thanks for all the suggestions!

断舍离 2024-09-23 22:27:15

当我使用管理员权限运行 .bat 文件时,日志文件中不会写入任何内容,并且该服务仍未安装。

首先,您必须以管理员权限运行。

其次,当您“以管理员身份运行”时,它实际上将目录更改为 c:\windows\system32 作为初始目录(不知道为什么),这可能可以解释为什么以管理员身份运行会导致没有日志文件。手动更改为脚本开头所在的路径 IEPPAMS_WinService1.exe。

When I run the .bat file with admin privileges nothing is written to the log file, and the service is still not installed.

First off, you HAVE to run as admin permissions.

Second, when you "Run as Administrator", it actually changes the directory to c:\windows\system32 as the initial directory ( no idea why ), which would probably explain why running as admin causes no log file. Manually change to the path IEPPAMS_WinService1.exe resides in that the start of your script.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文