Reputation: 195
I have created a windows application that start\stop windows service
now when i tried to start\stop sq-server engine from my application it throw an exception
when i run my Application as administrator it works
now i can run my application as administrator using app.manifest but the problem is that my client does not have permission as administrator
what type of permission my Application need and how to do that?
public static void start()
{
ServiceController sc = new ServiceController(ServiceName, ServerName);
sc.Start();
sc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running);
}
public static void stop()
{
ServiceController sc = new ServiceController(ServiceName, ServerName);
sc.Stop();
sc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped);
}
Upvotes: 1
Views: 182
Reputation: 3747
Your app is limited to the permissions of the person running it. If they don't have rights to do something, then neither will your application. You say that your client is not an administrator, so in order for your app to work for them an administrator will have to grant their login the permissions needed to start/stop services.
One of the following needs to happen:
For the 3rd option, this can be done at least a couple different ways:
Shift-right-click an application and it will give you a menu option to run as another user. This option requires someone to be there to enter their credentials every time you run the application this way.
Add the ability for someone to enter their credentials into your application and then impersonate them in your application when starting/stopping services. This method would allow you to give them the option to save their credentials for future use (not saying that's a good idea though).
Upvotes: 1