How to easily run an application as administrator without UAC prompts (PowerShell)

Introduction

This script sample can get all current url of tabs in Internet Explorer and supports automatically open the last opened urls.

Scenarios

Sometimes, a standard user will be able to use the "runas /savecred" command to run any command as administrator without entering a password. Perhaps user wants to allow a child's standard user account to run a game as Administrator without asking you, etc. This script can easily help you do it.

Note

This script will save credential of administrator account. You should be considered a security hole when appropriate.

And you'll need to enable the built-in Administrator account if the account was disabled.
Step 1: Start the PowerShell Console with administrator. To run the script in the Windows PowerShell Console, type the command< Script Path> at the Windows PowerShell Console.
Step 2:  If you want to know how to use this script. You can type the command Get-Help C:\Script\RunApplicationsAsAdmin.ps1 -Full to display the entire help file for this function, such as the syntax, parameters, or examples.

Example

Example 1: Type C:\Script\RunApplicationsAsAdmin.ps1 -ProgramPath "C:\Windows\system32\calc.exe" in the Windows PowerShell Console. 

This example shows how to create a shortcut of specified program on C:\Script.

 

As we can see, under the Script folder, the script generates a 'calc' shortcut file. We need to enter the administrator password when we use it at the first time.

Here are some code snippets for your references.

PowerShell
Edit|Remove
$FileName = (Get-Item -Path $ProgramPath).BaseName 
#create a new shortcut of program 
$ProgramShortcutPath = "$ScriptPath"+"$FileName.lnk" 
$ProgramShortcut = $WshShell.CreateShortcut($ProgramShortcutPath) 
$ProgramShortcut.TargetPath = "$Env:SystemRoot\system32\runas.exe" 
$ProgramShortcut.Arguments = "/user:$Env:COMPUTERNAME\Administrator /savecred $ProgramPath" 
$ProgramShortcut.Save() 
  
#change the default icon of shortcut 
$ProgramLnk = $Desktop.ParseName($ProgramShortcutPath) 
$ProgramLnkPath = $ProgramLnk.GetLink 
$ProgramLnkPath.SetIconLocation("$env:SystemRoot\System32\SHELL32.dll",111) 
$ProgramLnkPath.Save()

Prerequisite

Windows PowerShell 2.0 
Windows 7 or higher version

Microsoft All-In-One Script Framework is an automation script sample library for IT Professionals. The key value that All-In-One Script Framework is trying to deliver is Scenario-Focused Script Samples driven by IT Pros' real-world pains and needs. The team is monitoring all TechNet forums, IT Pros' support calls to Microsoft, and script requests submitted to TechNet Script Repository. We collect frequently asked IT scenarios, and create script samples to automate the tasks and save some time for IT Pros. The team of All-In-One Script Framework sincerely hope that these customer-driven automation script samples can help our IT community in this script-centric move.