Skip to content

Instantly share code, notes, and snippets.

@ebibibi
Created October 31, 2012 14:12
Show Gist options
  • Select an option

  • Save ebibibi/3987231 to your computer and use it in GitHub Desktop.

Select an option

Save ebibibi/3987231 to your computer and use it in GitHub Desktop.
Windowsを強制的に再起動した上で、次回ログオン時に指定したPowerShellスクリプトを1度だけ実行させます。
#第一引数にスクリプト名をフルパスで記述
#第二引数以降にスクリプトへの引数(複数指定可能)
$RegRunOnceKey = "HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce"
$powershell = (Join-Path $env:windir "system32\WindowsPowerShell\v1.0\powershell.exe")
$restartKey = "Restart-And-RunOnce"
$script = $args[0]
$newArgs = ""
for($i = 1; $i -le $args.Length; $i++)
{
$newArgs += " " + $args[$i]
}
#RunOnceキーにセット
Set-itemproperty -path $regrunoncekey -name $restartkey -value "$powershell $script$newargs"
Restart-Computer -Force
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment