cannot open window service on computer '.' in window application

三世轮回 提交于 2020-01-10 01:04:48

问题


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


回答1:


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.




回答2:


Go to c://Program Files/ApplicationFolder/.exe Right click on .exe and go to Properties then go Compability Tab and check true to Run this Program as an administrator Level.




回答3:


if you are using visual studio then close it and re open visual sudio with run it as administrator




回答4:


None of these solutions helped me, because it would help if I actually had ensured I had Administrator access on the target computer first! I was taking away and giving back Administrator access to my main account using my domain admin account. When I ran some ServiceController code that was checking if a service was running on a remote computer, under the domain admin account, all was fine. When I did it as my main account, that's when it didn't work - even when running Visual Studio as an Administrator. Turns out I had been testing without my main account in the local Admin group... d'oh!




回答5:


I ran into this with a scheduled task on a server--checking the "Run with highest privileges" solved it. (The service account has to have admin rights of course for this to work.)




回答6:


Framework version change in the app.conf to the version which is installed on the system fixed the issue for me.



来源:https://stackoverflow.com/questions/14501748/cannot-open-window-service-on-computer-in-window-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!