Running a Script to open a program as administrator

Welcome Forums General PowerShell Q&A Running a Script to open a program as administrator

This topic contains 2 replies, has 3 voices, and was last updated by

3 years, 2 months ago.

  • Author
  • #31562

    Points: 0
    Rank: Member

    Hi, I was wondering if it is possible to create a powershell script that uses the start-process command allowing me to open up a program (lets say cmd) as the administrator?
    The reason is I want the 'do you want to make changes to your pc....' sign to come up, in order for me to try use send keys to type in the password.

    I would appreciate some help as I am new to powershell. thanks.

  • #31567

    Points: 57
    Rank: Member

    Start-Process accepts a -Credential parameter which you can use to specify alternate credentials. This will help run the executable with credentials that will allow elevation, however you'll still be prompted to elevate.

    If you wish to immediately elevate, use the -Verb parameter with 'RunAs' as the value and that will automatically prompt you to run the process with an admin token. Credential and RunAs however are part of different parametersets therefore they cannot be run together.

    I'm not 100% clear on what it is exactly you're trying to do though? Could you elaborate?

  • #31569

    Points: 0
    Rank: Member

    try this

    $Username = 'Username'
    $Password = 'Password'
    $SecurePassword = ConvertTo-SecureString $Password -AsPlainText -Force
    $Credential = New-Object System.Management.Automation.PSCredential ($Username,$SecurePassword)
    Start-Process powershell.exe  -Credential $Credential -NoNewWindow -ArgumentList "(Start-Process -FilePath '\\some\path\app.exe' -ArgumentList  '/q).ExitCode"


The topic ‘Running a Script to open a program as administrator’ is closed to new replies.