Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I develop one window application and I also create one service. I start the service using coding in window application, but I am getting an error like cannot open window service on computer '.'

I have used below code.

ServiceController controller = new ServiceController("SeoMozScheduleService");

if (controller.Status == ServiceControllerStatus.Stopped)
{
    controller.Start();
}

If i right click on Application and click on Run as Administrator than it works fine for me...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
231 views
Welcome To Ask or Share your Answers For Others

1 Answer

To make this automatic every time you open the application you have to add a manifest file to your solution, then update the requestedExecutionLevel node inside the file to look like this:

    <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>

However, changing this setting will result in the system prompting you every time to run the application as administrator if UAC is enabled.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...