-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFallout4NoSleep.ps1
26 lines (24 loc) · 1.04 KB
/
Fallout4NoSleep.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#this prevents the powershell window from sticking around
Add-Type -Name win -MemberDefinition '[DllImport("user32.dll")] public static extern bool ShowWindow(int handle, int state);' -Namespace native
[native.win]::ShowWindow(([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle,0)
#this is the name of the process to monitor
$target = "Fallout4"
#this script will check every 60 seconds if the abovenamed process is running
#if it is, it will launch caffeine, wait for the process to end, then quit caffeine
$process = Get-Process | Where-Object {$_.ProcessName -eq $target}
while ($true)
{
while (!($process))
{
$process = Get-Process | Where-Object {$_.ProcessName -eq $target}
start-sleep -s 60
}
if ($process)
{
Start-Process -FilePath "ENTER_FILEPATH_HERE\caffeine.exe"
$process.WaitForExit()
start-sleep -s 5
$process = Get-Process | Where-Object {$_.ProcessName -eq $target}
Stop-Process -processname "caffeine"
}
}