我有 Apache Ant 文件 (build.xml),它被设置为创建我的生产服务器的自动备份。它被设置为停止 Apache 服务器和 MSSQL2000 - 备份所有内容并再次启动这两个服务(及其依赖项)。在旧的WIN 2008服务器下可以正常工作,但在WIN8下就不行了。当执行 .bat 文件来运行 Ant 进程时,它会打开 CMD(理应如此),但停止/启动操作均无法正确执行。我收到“访问被拒绝”的消息。回应。
这是执行.bat(Ant)文件时的CMD输出:
assemble:
stop.server.apache:
[exec] System error 5 has occurred.
[exec]
[exec] Access is denied.
[exec]
[exec] Result: 2
stop.server.ms-sql:
[exec] No valid response was provided.
[exec] The following services are dependent on the MSSQLSERVER service.
[exec] Stopping the MSSQLSERVER service will also stop these services.
[exec]
[exec] SQLSERVERAGENT
[exec]
[exec] Do you want to continue this operation? (Y/N) [N]:
[exec] Result: -1
[exec] System error 5 has occurred.
[exec]
[exec] Access is denied.
[exec]
[exec] Result: 2
负责启动/停止服务的实际 build.xml 部分如下:
......代码开始
<macrodef name="service">
<attribute name="service"/>
<attribute name="action"/>
<sequential>
<exec executable="cmd.exe">
<arg line="/c net @{action} '@{service}'"/>
</exec>
</sequential>
</macrodef>
<target name="start.server.ms-sql">
<service action="start" service="MSSQLSERVER"/>
<service action="start" service="SQLSERVERAGENT"/>
</target>
<target name="stop.server.ms-sql">
<service action="stop" service="SQLSERVERAGENT"/>
<service action="stop" service="MSSQLSERVER"/>
</target>
<target name="start.server.apache">
<service action="start" service="Apache2.2"/>
</target>
<target name="stop.server.apache">
<service action="stop" service="Apache2.2"/>
</target>
......更多代码在这里
我已经启用了所有磁盘/文件夹权限以确保它不受影响(我知道 Vista 及更高版本中存在权限更改。我还研究了 Apache Ant documentation 但我找不到任何有关停止/启动服务的信息具有更高的权限。
有什么想法吗?
注意:Apache2.2 和 MSSQL 从驱动器 W:\运行,Win 操作系统从 C: 运行。我的 Ant 路径设置正确,但我认为这可能会导致权限访问问题。
最佳答案
此错误与 ant 无关(直接)。 Windows8(实际上Windows Vista和7也是)有UAC。即使用户使用管理帐户登录,也无法启动服务。您将拥有我们run-as
管理员。通常,这可以作为右键单击菜单使用。
要使脚本获得相同的效果,您可以禁用 UAC。 (这里是instructions for windows 7 )。 Windows 8 可能有类似的指令。
这个问题的一些详细讨论,可能对你有用:How can I auto-elevate my batch file, so that it requests from UAC administrator rights if required?
关于ant - Apache Ant - 启动/停止 win 服务 - 访问被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19169505/