1

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.

2 Answers 2

2

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/

Sign up to request clarification or add additional context in comments.

3 Comments

I can right click on Powershell.lnk and click "run as administrator" and enter user and password and run my command, but i want to do this in c# with existing administrator's username and password.
with existing administrator's username and password. Isn't it that, what @Payam worte? Starting your app, it would either run privileged or ask for credentials to a privileged user. Or do you try to run your code as different user?
@CodeMan there are two approaches to getting this done. First, you can execute the PowerShell script in C#, which is the one that I have provided. Second, you can execute a PowerShell file. Both need administrative privilege which I have included.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.