0

I need to install a windows service from inside my Java application. I have a bat file, that does that. Thing is, it needs elevation.

How can I easily do that from my Java code?

I've looked here: Elevating a ProcessBuilder process via UAC? and it seems like a freakishly large code for such a simple operation. Is there an easier way? That thread is 3 y.o., so maybe something happend since then?

Community
  • 1
  • 1
SMSk
  • 693
  • 8
  • 25

1 Answers1

0

If you start your application with elevated permissions it should do the trick from what I remember.

The alternative is that you wrap the bat file in say an exe that has a manifest file that requires elevated permissions. This will prompt the UAC.

See this SO post about creating bat files with elevated permissions. Elevating batch permissions

Community
  • 1
  • 1
gwnp
  • 1,127
  • 1
  • 10
  • 35
  • My application is deployed to Tomcat, so... How about a manifest for bat file? Can I do that? – SMSk Jul 08 '15 at 14:10
  • You could still wrap the bat file in an exe that tomcat calls, but I have edited my answer to point to a SO question about elevating batch file permissions. http://stackoverflow.com/questions/7044985/how-can-i-auto-elevate-my-batch-file-so-that-it-requests-from-uac-administrator Hope this helps. – gwnp Jul 08 '15 at 14:34
  • I think you could also do this with a shortcut, using the option to run the target as an administrator. – Harry Johnston Oct 23 '15 at 20:44