Ankush Butole
Ankush Butole

Reputation: 151

Not able to stop the service on UWP appx launch

I have created appx using makeappx tool. After installing appx,on launch I have added below code to stop the service:

ServiceController sc = new ServiceController("MyService");
    string servicestatus = sc.Status.ToString();
    if (servicestatus == "Running")
    {
     sc.Stop();
    }

On launch I found the service was not stop and getting an exception.But when I run the same appx from start menu with run as administrator I found service was getting stop. I think the issue was related with admin previlages as I know appx always launch with fulltrustprocess and not with adminprevilages. It will be great help if we can stop the service on appx launch itself.

Upvotes: 0

Views: 123

Answers (1)

Peter Torr
Peter Torr

Reputation: 12019

This is to be expected; if you launch CMD as a normal user and try to stop a service, you will get Access Denied:

C:\Users\Peter>net stop "Bonjour Service"
System error 5 has occurred.

Access is denied.

When running elevated, it works:

C:\Users\Administrator>net stop "Bonjour Service"
The Xamarin Bonjour Service service is stopping.
The Xamarin Bonjour Service service was stopped successfully.

Apps converted via the Desktop Bridge cannot auto-elevate; the user has to do that.

Upvotes: 1

Related Questions