Skip to content

Instantly share code, notes, and snippets.

@linnet8989
Created May 2, 2018 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linnet8989/139229b18f3bc4fb354544b6eb674f3e to your computer and use it in GitHub Desktop.
Save linnet8989/139229b18f3bc4fb354544b6eb674f3e to your computer and use it in GitHub Desktop.
run powershell.exe/cmd.exe as Administrator in powershell and use current working directory as its working directory
# open a new powershell
# full version:
$arg = '-NoExit -Command "& {cd '+ "'" + $pwd + "'"+ '}"'
Start-Process Powershell -ArgumentList $arg -Verb runAs
# simplified version:
$arg = '-noexit -c "& {cd '+ "'" + $pwd + "'"+ '}"'
start powershell -a $arg -v runas
# open a new cmd
# full version:
$arg = '/k cd "' + $pwd + '"'
Start-Process cmd -ArgumentList $arg -Verb runAs
# simplified version:
$arg = '/k cd "' + $pwd + '"'
start cmd -a $arg -v runas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment