Windows/PowerShell.md
... ...
@@ -233,6 +233,26 @@ Get-Service ssh-agent
233 233
```
234 234
- [Visual Studio Code Remote Development Troubleshooting Tips and Tricks](https://code.visualstudio.com/docs/remote/troubleshooting#_setting-up-the-ssh-agent)
235 235
236
+# 多重起動防止
237
+```powershell
238
+$mutex = New-Object System.Threading.Mutex($false, "Global\myAppName")
239
+$hasHandle = $true
240
+try {
241
+ $hasHandle = $mutex.WaitOne(0, $false)
242
+ if (-not $hasHandle) {
243
+ Write-Warning "Already running."
244
+ exit
245
+ }
246
+ # 本来の処理
247
+}
248
+finally {
249
+ if ($hasHandle) {
250
+ $mutex.ReleaseMutex()
251
+ }
252
+ $mutex.Close()
253
+}
254
+```
255
+
236 256
# PowerShell Core のインストール
237 257
- [PowerShell のさまざまなバージョンのインストール](https://docs.microsoft.com/ja-jp/powershell/scripting/install/installing-powershell)
238 258
- [Windows への PowerShell Core のインストール](https://docs.microsoft.com/ja-jp/powershell/scripting/install/installing-powershell-core-on-windows)