Board logo

标题: [转载代码] [PowerShell每日技巧]提权执行命令(20140319) [打印本页]

作者: DAIC    时间: 2014-3-25 15:28     标题: [PowerShell每日技巧]提权执行命令(20140319)

Sometimes, a script may need to run a command that needs elevation (Administrator privileges).

Instead of requiring the script to run with full privileges altogether, you can also send individual commands to an elevated shell.

This will restart the Spooler driver (which requires elevated privileges), and sends the command to another PowerShell process. It will automatically start elevated if the current process does not have Administrator privileges.
  1. $command = 'Restart-Service -Name spooler'
  2. Start-Process -FilePath powershell.exe -ArgumentList "-noprofile -command $Command" `
  3. -Verb runas
复制代码
http://powershell.com/cs/blogs/tips/archive/2014/03/19/running-commands-elevated-in-powershell.aspx




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2