I am in the middle of a problem. I am trying to start a windows service from java. My OS is windows 7. And I am logged in the machine a my user name (not administrator). I have administrator privilege. I can start the service from the service list. From my java code I am trying to start the same windows service. But from windows 7 I am unable start the service from my java code. Access denied error is returning. When I start the my java application as administrator (right clicking the application icon and start as administrator) I can start the same service. Can somebody help me regarding this?
When you're calling your code like that, it's not being executed as Administrator but as yourself. Even though you may have administrative rights, User Access Control (UAC) probably still won't let you do it without confirmation. The problem is, that confirmation dialog is suppressed when you try to execute the command through Java. Try using the runas command:
You will probably be prompted for the password though; I don't really know how to prevent that (or even what the password is, as I've never set one; the user is even disabled on my machine).