0

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)

1

2 Answers 2

1

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.

0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .