Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, January 29, 2014 4:24 AM
I need to open service through my C# application and currently when I run the application it says that Windows cannot open that service on this computer, How do I open the service with admin rights through the code? I am currently logged in as admin though.
mayooran99
All replies (2)
Wednesday, January 29, 2014 7:17 AM
Hi, logged in as admin is not enough, you need to run your application as administrator if you want to control Windows service, you can save below xml to a file app.manifest, and then add app.manifest to your project.
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
<applicationRequestMinimum>
<defaultAssemblyRequest permissionSetReference="Custom" />
<PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />
</applicationRequestMinimum>
</security>
</trustInfo>
</asmv1:assembly>
and in project setting, please go to Application tab, and select the app.manifest file, see below
and then rebuild your project. When finish, you application will be run as administrator when it start.
Wednesday, January 29, 2014 9:01 AM
I have copied the manifest file and then did a rebuild. When I run the program, Visual Studio restarts and program restarts again. Still it says that this service cannot be started on this machine.
mayooran99