Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I only have one account on my Windows Vista machine, and that user has administrative privileges. However, when I try to execute a command within PowerShell to kill a certain process, I'm greeted with an "Access is denied" message. How do I become the administrator?

share|improve this question

4 Answers 4

up vote 11 down vote accepted

The easiest way to do this is to launch Powershell with administration tokens. To do this, you right click on Powershell (or a shortcut to it) and click on "run as administrator". Alternatively you can use elevate.cmd.

share|improve this answer

This opens a new powershell instance:

function Run-Elevated ($scriptblock)
{
  # TODO: make -NoExit a parameter
  # TODO: just open PS (no -Command parameter) if $sb -eq ''
  $sh = new-object -com 'Shell.Application'
  $sh.ShellExecute('powershell', "-NoExit -Command $sb", '', 'runas')
}

I expect that there are issues with this - in particular, you won't get the output of your scriptblock back in the calling script. On the other hand, it will be there in the new PS instance so you can hack with it there.

share|improve this answer

If you want to always run PowerShell with admin priveleges, you can right-click the PowerShell shortcut, then click the "Advanced..." button on the "Shortcut" tab, then select "Run as Administrator".

share|improve this answer

The Powershell v2 way, according to Microsoft, is to right click on the shortcut and choose Run as Administrator.

And to elevate within a Powershell window:

start-process powershell –verb runAs

Which from a cmd.exe batch file, shortcut or Run line would look something (repetitively) like this:

powershell -nologo "start-process powershell -verb runas"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.