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
:
<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>
The problem that I'm running into is, that to be able to control services, you need to have adminsitrative rights. My user is local admin so the script works if I run it in an elevated prompt (right click->'Run as Adminsitrator').
I've tried using runas /user:administrator
but it's prompting for a password. I could run the Maven build itself as admin but I'd like to run it from environments where this might not be possible (Eclipse, Jenkins).
Does anyone have an idea on how to implement the described scenario?
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:
I copied the resulting .exe into my project folder and changed the
exec-maven-plugin
configuration toThe 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
This is the other half of my solution to elevation mkdir in batch file as admin. The first half was console specific. This is the more general non console solution.
WshShell.Run
didn't work well as a console program, hence the use of VB/VBAshell
command. TheWshShell.Run
has a window style (0 is hidden) and a flag to wait on the app or not.Put files on the desktop. They must be ANSI.
RunAsAdmin.vb
RunAsAdmin.manifest
And the command to compile.