Last active
December 13, 2024 14:29
-
-
Save s-hiiragi/3ca8bfa012d964094ad12e38a76ebdfa to your computer and use it in GitHub Desktop.
ウィンドウを閉じるとクリーンアップ処理を開始するスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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