# ============================================================================== # Setup Startup Task and Shortcut for MusicDownloader Auto-Mount # ============================================================================== $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 $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) $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) 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" } catch { Write-Warning "[Warning] Failed to register ScheduledTask: $_" } Write-Host "Setup completed successfully."