LoginSignup
35
40

More than 5 years have passed since last update.

管理者権限ダイアログを出さずにpowershellスクリプトを管理者権限で実行

Posted at

管理者権限昇格ダイアログを出さずにpowershellのスクリプトを実行させるのが、かなり手間がかかってしまったので忘れないよう手順をメモしておきます。

1.PowerShellを管理者権限で起動するbatファイルを作成
test.bat:
  @powershell -Command "Start-Process powershell.exe -ArgumentList c:\temp\test.ps1 -Verb runas"

2.タスクスケジューラーに上記のbatを起動するタスクを作成する。
 [全般-最上位の特権で実行する]にチェックを入れる

3.上記で作成したタスクを起動するbatファイルを作成
trigger.bat:
  schtasks.exe /run /tn test

4.trigger.batを起動する
 UACダイアログを出さずにPowerShellを起動することが可能

参考
 http://www.losttechnology.jp/Win7/taskscheduler.html
 http://scripting.cocolog-nifty.com/blog/2009/12/uac-ddfc.html

35
40
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
35
40