Jon
Jon

Reputation: 4045

Create a Windows Service from within Java

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?

Upvotes: 0

Views: 680

Answers (3)

epenn
epenn

Reputation: 46

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.

Upvotes: 1

Tayyab
Tayyab

Reputation: 10631

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

Upvotes: 1

Erik
Erik

Reputation: 91270

You cannot. Adding a service requires administrator privileges.

Upvotes: 0

Related Questions