Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

start windows service from windows 7 from java

 
shihab K Bava
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

My source code given below.

 
Rob Spoor
Sheriff
Pie
Posts: 20532
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic