Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have developed a program in Java that uses on a local SQL Server instance to store its data. On some installations the SQL Server instance is not running sometimes.

Users can fix this problem by manually starting the SQL Server instance (via services.msc).

I am thinking about automating this task: the software would check if the database server is reachable, if not try to (re)start it. The problem is that on the same user account the Services can be stopped /started via services.msc (without any UAC prompt), but not via (non-elevated) command line.

The operating system seems to treat services.msc differently:

c:\>sc start mssql$db1

[SC] StartService: OpenService FEHLER 5:
Zugriff verweigert (Access denied)

 c:\>net start mssql$db1

Systemfehler 5 aufgetreten. Zugriff verweigert (Access denied)

So the question is: how can I stop/start the service from a java-program/command line without having my users to use services.msc (preferrably via on-board-tools)

share|improve this question
You have to elevate the prompt itself or it will not work. That, or change UAC appropriately, or try the PowerTools for this purpose as others have. – songei2f Jul 13 '11 at 10:18

In a standard Windows 7 setup, if you run 'services.msc' as a non elevated administrator, it will start up as an elevated process (Integrity Level is 'High').

That's why you can use services.msc to start and stop services.

In Vista, you would have gotten a UAC prompt. In Windows 7 Microsoft softened UAC a bit to make it less annoying. Windows assumes you want to run services.msc elevated, because it doesn't really make sense to run it non-elevated.

You can change the Win7 UAC settings to 'Always notify', now if you open services.msc, you'll get the UAC prompt.

All this does not really help with your problem, if the user can not open an elevated command prompt to use 'sc' or 'net start', he/she will not be able to start a service.

In your setup-batch, check whether it runs elevated and if not display a message or start an elevated prompt and let the user handle the UAC dialog.

share|improve this answer

Perhaps you can set the right privileges using the sc.exe command. See this MSDN article for details.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.