Skip to content

Instantly share code, notes, and snippets.

@jalbertbowden
Last active July 23, 2019 14:39
Show Gist options
  • Select an option

  • Save jalbertbowden/c3bd46c29ac59e13ca640105cd990c44 to your computer and use it in GitHub Desktop.

Select an option

Save jalbertbowden/c3bd46c29ac59e13ca640105cd990c44 to your computer and use it in GitHub Desktop.
Powershell Script calling Batch Script to kill Firefox and Chrome running in Windows.
Add-Type @'
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace PInvoke.Win32 {
public static class UserInput {
[DllImport("user32.dll", SetLastError=false)]
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
[StructLayout(LayoutKind.Sequential)]
private struct LASTINPUTINFO {
public uint cbSize;
public int dwTime;
}
public static DateTime LastInput {
get {
DateTime bootTime = DateTime.UtcNow.AddMilliseconds(-Environment.TickCount);
DateTime lastInput = bootTime.AddMilliseconds(LastInputTicks);
return lastInput;
}
}
public static TimeSpan IdleTime {
get {
return DateTime.UtcNow.Subtract(LastInput);
}
}
public static int LastInputTicks {
get {
LASTINPUTINFO lii = new LASTINPUTINFO();
lii.cbSize = (uint)Marshal.SizeOf(typeof(LASTINPUTINFO));
GetLastInputInfo(ref lii);
return lii.dwTime;
}
}
}
}
'@
ForEach ($i in 0..9) {
Write-Host ("Last input " + [PInvoke.Win32.UserInput]::LastInput)
Write-Host ("Idle for " + [PInvoke.Win32.UserInput]::IdleTime)
Start-Sleep -Seconds (Get-Random -Minimum 1 -Maximum 5)
}
@echo off
for /f "tokens=1 delims=" %%# in ('qprocess^|find /i /c /n "MicrosoftEdg"') do (
set count=%%#
)
taskkill /F /IM MicrosoftEdge.exe /T
taskkill /F /IM firefox.exe /T
pause
start-process "C:\Users\Albert Bowden\Desktop\powershell-scripts\kill-browsers.bat"
$prompt = new-object -comobject wscript.shell
$answer = $prompt.popup("Are you still using the Internet?`n",5,"Alert Modal",3)
if($answer -eq 6) {Write-Host "Yes was selected"}
if($answer -eq 7) {Write-Host "No was selected"}
if($answer -eq -1) {Write-Host "Timed out" }
if($answer -eq 2) {Write-Host "Canceled by user."}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment