How can I run PowerShell as administrator with Terminal in Sublime Text 3?
Here is the default configuration:
{
// The command to execute for the terminal, leave blank for the OS default
// See https://github.com/wbond/sublime_terminal#examples for examples
"terminal": "",
// A list of default parameters to pass to the terminal, this can be
// overridden by passing the "parameters" key with a list value to the args
// dict when calling the "open_terminal" or "open_terminal_project_folder"
// commands
"parameters": [],
// An environment variables changeset. Default environment variables used for the
// terminal are inherited from sublime. Use this mapping to overwrite/unset. Use
// null value to indicate that the environment variable should be unset.
"env": {}
}
Option 1: Run Sublime Text as administrator. The process started by the Terminal plugin will run under the administrator user as well. Be careful—third-party plugins will also have admin privileges.
Option 2: Configure the Terminal plugin to start a new PowerShell instance that runs as an administrator:
"terminal": "powershell.exe",
"parameters": [
"-WindowStyle", "Hidden",
"-Command", "Start-Process", "-Verb", "RunAs", "powershell.exe",
"-ArgumentList", "'-NoExit', '-Command', Set-Location, \"'$PWD'\""
],
This configuration launches a command that restarts PowerShell under an admin user. We manually reset the working directory because the new instance starts in a different process space. When UAC is enabled, we'll need to confirm execution within the UAC prompt that appears to escalate privileges. If desired, we can disable the prompt for a specific program.