The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Y
By Guest on 5th July 2025 05:56:00 AM | Syntax: TEXT | Views: 1



New paste | Download | Show/Hide line no. | Copy text to clipboard
  1. # Install-SmartSleep.ps1 - Run as Administrator
  2.  
  3. # Create Scripts directory
  4. $scriptPath = "C:\Scripts"
  5. if (-not (Test-Path $scriptPath)) {
  6.     New-Item -ItemType Directory -Path $scriptPath -Force
  7.     Write-Host "Created directory: $scriptPath" -ForegroundColor Green
  8. }
  9.  
  10. # Check if main script exists
  11. $mainScript = "$scriptPath\SmartSleep.ps1"
  12. if (-not (Test-Path $mainScript)) {
  13.     Write-Host "ERROR: Please save SmartSleep.ps1 to C:\Scripts\ first!" -ForegroundColor Red
  14.     exit 1
  15. }
  16.  
  17. # Set execution policy for scripts
  18. try {
  19.     Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine -Force
  20.     Write-Host "Set execution policy to RemoteSigned" -ForegroundColor Green
  21. }
  22. catch {
  23.     Write-Host "Warning: Could not set execution policy. Run as Administrator." -ForegroundColor Yellow
  24. }
  25.  
  26. # Remove existing task if present
  27. $existingTask = Get-ScheduledTask -TaskName "SmartSleepMonitor" -ErrorAction SilentlyContinue
  28. if ($existingTask) {
  29.     Unregister-ScheduledTask -TaskName "SmartSleepMonitor" -Confirm:$false
  30.     Write-Host "Removed existing scheduled task" -ForegroundColor Yellow
  31. }
  32.  
  33. # Create scheduled task
  34. $taskAction = New-ScheduledTaskAction -Execute "powershell.exe" `
  35.     -Argument "-WindowStyle Hidden -NoProfile -ExecutionPolicy Bypass -File `"$mainScript`""
  36.  
  37. $taskTrigger = New-ScheduledTaskTrigger -AtStartup
  38.  
  39. $taskSettings = New-ScheduledTaskSettingsSet `
  40.     -AllowStartIfOnBatteries `
  41.     -DontStopIfGoingOnBatteries `
  42.     -StartWhenAvailable `
  43.     -RestartCount 3 `
  44.     -RestartInterval (New-TimeSpan -Minutes 1) `
  45.     -ExecutionTimeLimit (New-TimeSpan -Hours 0)
  46.  
  47. $taskPrincipal = New-ScheduledTaskPrincipal `
  48.     -UserId "SYSTEM" `
  49.     -LogonType ServiceAccount `
  50.     -RunLevel Highest
  51.  
  52. $task = New-ScheduledTask `
  53.     -Action $taskAction `
  54.     -Trigger $taskTrigger `
  55.     -Settings $taskSettings `
  56.     -Principal $taskPrincipal `
  57.     -Description "Monitors system idle time and forces sleep when games are idle but not during media playback"
  58.  
  59. # Register the task
  60. Register-ScheduledTask `
  61.     -TaskName "SmartSleepMonitor" `
  62.     -InputObject $task `
  63.     -Force
  64.  
  65. Write-Host "`nScheduled task created successfully!" -ForegroundColor Green
  66.  
  67. # Start the task immediately
  68. Start-ScheduledTask -TaskName "SmartSleepMonitor"
  69. Write-Host "Smart Sleep Monitor is now running" -ForegroundColor Green
  70.  
  71. # Create desktop shortcut for logs
  72. $WshShell = New-Object -comObject WScript.Shell
  73. $Shortcut = $WshShell.CreateShortcut("$env:USERPROFILE\Desktop\SmartSleep Log.lnk")
  74. $Shortcut.TargetPath = "notepad.exe"
  75. $Shortcut.Arguments = "$scriptPath\SmartSleep.log"
  76. $Shortcut.Save()
  77. Write-Host "`nCreated desktop shortcut to view logs" -ForegroundColor Cyan
  78.  
  79. # Display status
  80. Write-Host "`n=== Installation Complete ===" -ForegroundColor Green
  81. Write-Host "The Smart Sleep Monitor is now:"
  82. Write-Host "  ✓ Installed as a system service" -ForegroundColor Green
  83. Write-Host "  ✓ Running in the background" -ForegroundColor Green
  84. Write-Host "  ✓ Will start automatically on boot" -ForegroundColor Green
  85. Write-Host "`nLog file: $scriptPath\SmartSleep.log"
  86. Write-Host "To uninstall, run: Unregister-ScheduledTask -TaskName 'SmartSleepMonitor'" -ForegroundColor Yellow



  • Recent Pastes