我正在尝试设置一个构建过程,在此过程中,必须启动和停止Windows服务。我尝试使用exec-maven-plugin
:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>startServer</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${project.basedir}/bin/startService.cmd</executable>
<workingDirectory>${project.basedir}/bin</workingDirectory>
</configuration>
</execution>
</executions>
</plugin>
我遇到的问题是,要能够控制服务,您需要拥有托管权。我的用户是本地管理员,因此,如果我在高架提示中运行脚本(右键单击 ->'As As AdminSitrator')。
)。我已经尝试使用runas /user:administrator
,但是它正在提示密码。我可以作为管理员运行Maven构建,但我想从可能无法实现的环境中运行它(Eclipse,Jenkins)。
有人对如何实现所描述的方案有想法吗?
这是我作为管理文件中高程mkdir解决方案的另一半。上半场是专有控制台的。这是更通用的非控制台解决方案。WshShell.Run
作为控制台程序的工作状态不佳,因此使用VB/VBA shell
命令。WshShell.Run
具有窗口样式(0是隐藏的)和一个在应用程序上等待的标志。
将文件放在桌面上。他们必须是ansi。
runasadmin.vb
imports System.Runtime.InteropServices
Public Module MyApplication
Public Sub Main ()
Dim wshshell as object
WshShell = CreateObject("WScript.Shell")
'8 is non active window, true means wait for exit
WshShell.Run("""C:WindowsNotepad.exe""",8, true)
End Sub
End Module
runasadmin.manifest
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="*"
name="Color Management"
type="win32"
/>
<description>Serenity's Editor</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
和要编译的命令。
C:WindowsMicrosoft.NETFrameworkv4.0.30319vbc "%userprofile%DesktopRunAsAdmin.vb" /win32manifest:"%userprofile%DesktopRunAsAdmin.manifest" /out:"%userprofile%DesktopRunAsAdmin.exe" /target:winexe
多亏了@acatinlove,我有一个工作解决方案。它基于他们对批处理文件中的mkdir的答案
问题在于它正在开始新的外壳,而不是等待批处理脚本完成。我必须修改脚本才能这样做。我发现A是在如何等待外壳过程完成之前完成vb6
执行进一步代码的方法。这是脚本:
imports System.Runtime.InteropServices
Public Module MyApplication
Public Sub Main ()
Dim hProcess As Long
Dim taskId As Long
Dim wshshell as object
WshShell = CreateObject("WScript.Shell")
taskId = Shell("cmd /c " & Command())
hProcess = OpenProcess(&H100000, True, taskId)
Call WaitForSingleObject(hProcess, 10000)
CloseHandle(hProcess)
End Sub
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
End Module
我将结果.exe复制到我的项目文件夹中,并将exec-maven-plugin
配置更改为
<executable>..RunAsAdminConsole.exe startService.cmd</executable>
唯一的限制是UAC弹出,但我期待的。
我现在将我的问题向其他建议开放。请在Mkdir in Batch File in Admin