I\'m trying to set up a build process during which, a Windows service has to be started and stopped. I tried doing that by using the exec-maven-plugin:
Thanks to @ACatInLove I have one working solution. It is based on their answer to mkdir in batch file as admin
The problem was that it was starting a new shell and not waiting for the batch script to finish. I had to modify the script to do so. I found a was to do that at How to wait for a shell process to finish before executing further code in VB6
This is the script:
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
I copied the resulting .exe into my project folder and changed the exec-maven-plugin configuration to
..\RunAsAdminConsole.exe startService.cmd
The only restriction is that UAC pops up but I was anticipating that.
I will leave my question open to other suggestions for now. Please give @ACatInLove some credit over at mkdir in batch file as admin