question

MohamedGADER-3104 avatar image
0 Votes"
MohamedGADER-3104 asked Paul-5034 answered

restart service from Windows Form

Hi, I want to create a windowsform c# to restart remotely service from non admin poste I have always access denied

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Paul-5034 avatar image
0 Votes"
Paul-5034 answered

I'm assuming you're trying to call ServiceController.Restart and it's throwing an exception. This is because if you have UAC enabled for your Windows user then you'll need to run your application as an Adminstrator.

The easiest way to do that is to add an app.manifest to your project, if you right click on your project and go to "Add > New Item" then search in the top right search box for "manifest", double click the template it gives you, then in the app.manifest file it's created for you there should be a line that looks like this:

 <requestedExecutionLevel level="asInvoker" uiAccess="false" />

Change it to this, build and try and run your app again:

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

Before the app runs you'll get a UAC dialog requesting administrative access, so just allow it access and then it should remember that setting and you should be able to start/stop/restart services.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.