CodeMan
CodeMan

Reputation: 706

Run a PowerShell script with Administrator privileges on other computer

My user haven't got access to run PowerShell.exe

Using C# I want to be able to run

(Get-Service -ComputerName 172.x.x.x -Name mssqlserver).Start()

on another computer, as the domain administrator account.

I can run PowerShell as administrator's username and password.

I searched in StackOverFlow... but I did not found my answer.

Upvotes: 1

Views: 3165

Answers (2)

CodeMan
CodeMan

Reputation: 706

I found it !!!! I build my application and run it to create application.exe then run it as administrator !! in this way I can run all of my scripts without any error ! :^) thanks.

Upvotes: 0

Payam Lashkari
Payam Lashkari

Reputation: 31

If you need an administrative privilege when executing your application, you should add below element in the application's manifest file:

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

For executing a PowerShell script you can also use the below link. I have used this library before and it works fine. https://blogs.msdn.microsoft.com/kebab/2014/04/28/executing-powershell-scripts-from-c/

Upvotes: 2

Related Questions