Skip to content

Instantly share code, notes, and snippets.

@s-hiiragi
Last active December 13, 2024 14:29
Show Gist options
  • Save s-hiiragi/3ca8bfa012d964094ad12e38a76ebdfa to your computer and use it in GitHub Desktop.
Save s-hiiragi/3ca8bfa012d964094ad12e38a76ebdfa to your computer and use it in GitHub Desktop.
ウィンドウを閉じるとクリーンアップ処理を開始するスクリプト
Param(
# 内部的な引数
[switch]$Hidden,
# 内部的な引数
[switch]$Perform
)
if (-not $Hidden -and -not $Perform) {
# PowerShellウィンドウを非表示で実行
powershell -WindowStyle Hidden -File $MyInvocation.MyCommand.Path -Hidden
}
elseif ($Hidden) {
# 閉じるとクリーンアップ処理が始まるコマンドプロンプトを開く
Start-Process -Wait -WindowStyle Minimized -FilePath "$env:comspec" -ArgumentList "/K","`"echo このウィンドウを閉じるとクリーンアップ処理を実行します。`""
Start-Process -FilePath "$PsHome\powershell.exe" -ArgumentList "-File",$MyInvocation.MyCommand.Path,"-Perform"
}
elseif ($Perform) {
# クリーンアップ処理
echo "クリーンアップ処理中です"
pause
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment