refactor: auto-mount スクリプトの改善(マウント健全性チェック方式を刷新)
This commit is contained in:
1 parent
8f6ab47363
commit
54881f5d68
2 files changed
+42
-52
No files matched your search
+11
-10
@@ -1,4 +1,4 @@
|
||||
# ==============================================================================
|
||||
# ==============================================================================
|
||||
# Setup Startup Task and Shortcut for MusicDownloader Auto-Mount
|
||||
# ==============================================================================
|
||||
|
||||
@@ -6,23 +6,24 @@ $scriptDir = "C:\VS2026\MusicDownloader"
|
||||
$vbsPath = Join-Path $scriptDir "run-auto-mount-silent.vbs"
|
||||
$ps1Path = Join-Path $scriptDir "auto-mount-gdrive.ps1"
|
||||
|
||||
# 1. Register to Startup Folder
|
||||
# 1. Register to Startup Folder (PC起動時・ログオン時の即座実行用)
|
||||
$startupFolder = [Environment]::GetFolderPath([Environment+SpecialFolder]::Startup)
|
||||
$startupVbs = Join-Path $startupFolder "MusicDownloader-AutoMount.vbs"
|
||||
Copy-Item -Path $vbsPath -Destination $startupVbs -Force
|
||||
Write-Host "[OK] Startup folder configured: $startupVbs"
|
||||
|
||||
# 2. Register to Windows Task Scheduler (At Logon)
|
||||
# 2. Register to Windows Task Scheduler (5分ごとの定期ヘルスチェック&自動復旧用)
|
||||
$taskName = "MusicDownloader-AutoMount"
|
||||
$action = New-ScheduledTaskAction -Execute "wscript.exe" -Argument "`"$vbsPath`""
|
||||
$trigger = New-ScheduledTaskTrigger -AtLogOn
|
||||
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit (New-TimeSpan -Minutes 10)
|
||||
$taskCmd = "wscript.exe $vbsPath"
|
||||
|
||||
try {
|
||||
# 既存タスクがあれば上書き登録
|
||||
Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue
|
||||
Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Settings $settings -Description "Auto-mounts Google Drive (G:) to WSL2 and recovers MusicDownloader container on logon" | Out-Null
|
||||
Write-Host "[OK] Task Scheduler configured: $taskName"
|
||||
# schtasks を用いて一般ユーザー権限でも登録可能な5分毎タスクを作成
|
||||
& schtasks /create /tn $taskName /tr $taskCmd /sc minute /mo 5 /f | Out-Null
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Host "[OK] Task Scheduler configured (every 5 mins): $taskName"
|
||||
} else {
|
||||
Write-Warning "[Warning] schtasks failed with exit code: $LASTEXITCODE"
|
||||
}
|
||||
} catch {
|
||||
Write-Warning "[Warning] Failed to register ScheduledTask: $_"
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user