Reputation: 1085
I have my own application server which is windows service who communicates with the sql server, in some cases sql server service is stop so I am stating that via this code
ServiceController sc = new ServiceController("MSSQL$SQLEXPRESS");
sc.Start();
sc.WaitForStatus(ServiceControllerStatus.Running);
but it requires administrator privileges to start service how can I start my window service as administrator
Upvotes: 8
Views: 19654
Reputation: 2422
Lets split everything into steps
All information could be a little bit different based on you situation. More info
<?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>
Upvotes: 6
Reputation: 1085
i just add this tag in my app.manifest file
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
it works ...
Upvotes: 6