Create a Windows Service from within Java

天涯浪子 提交于 2019-12-08 11:17:06

问题


I have a Java program and I need to create a Windows Service from within that Java program. I want to basically run the command line

sc create \"" + serviceName + "\" binPath= \"" + batFile + "\" start= auto

However, when I run this process from within Java I get an error

[SC] OpenSCManager FAILED 5:

Access is denied.

This command works fine if the user is an administrator, however my users of this Java program will not be administrators. How do I create a Windows Service from within Java (or by running external programs) without the user having administrator privileges?

Edit: Apparently this isn't possible. Is there another way in Windows to execute a program at machine start up other than through a Windows Service?


回答1:


It is not possible to create service in windows without Administrator privileges.




回答2:


It isn't possible to create a windows service without Administrator privileges. Similarly, you won't be able to launch any executables through the System Configuration Utility's startup tab (msconfig). If you're unable to obtain Administrator privileges, would it be enough to create a shortcut in your account's startup folder?

If this is something you need just for you then that should do the trick. If this is something you'll need for multiple user accounts you'll need to be an Administrator.




回答3:


You cannot. Adding a service requires administrator privileges.



来源:https://stackoverflow.com/questions/5265883/create-a-windows-service-from-within-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!