LoginSignup
15
11

More than 5 years have passed since last update.

PowerShellで管理者モードのプロセス起動

Last updated at Posted at 2016-11-29

通常のコマンドラインからサービスの起動停止ができなかったので調べてみました。

PowerShellで管理者モードのコマンドプロンプトやPowerShellを起動する。

start-process "cmd.exe" -Verb runas
start-process "powershell.exe" -Verb runas

例)コマンドプロンプトからサービスの起動停止

powershell.exe -command start-process 'cmd.exe' '/c sc start mpssvc' -Verb runas
powershell.exe -command start-process 'cmd.exe' '/c sc stop mpssvc' -Verb runas

scコマンドの代わりにnetコマンド、Start-Service、Stop-Serviceでも大丈夫です。

管理者モードでないと実行できないコマンドレットの実行

ネットワーク関連の設定などで管理者モードでないと実行できない場合はPowerShellから管理者モードでPowerShellを起動してからコマンドレットを実行する。なんか、まわりくどいけどこうするしかないみたい。
例えば、ネットワークアダプタを無効にする時とか。
※"Ethernet"はアダプタ名

powershell.exe -command start-process 'powershell.exe' '-command Disable-NetAdapter -Name "Ethernet" -Confirm:$false' -Verb runas
15
11
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
15
11