am shammout
am shammout

Reputation: 195

start sql server engine permission

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

Answers (1)

BVernon
BVernon

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:

  1. The user needs to get admin rights
  2. An admin needs to assign the user permissions to start/stop services
  3. Your program will need to be run under alternate credentials

For the 3rd option, this can be done at least a couple different ways:

  1. 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.

  2. 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

Related Questions