-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-ActiveWindow.ps1
More file actions
56 lines (53 loc) · 1.59 KB
/
Copy pathGet-ActiveWindow.ps1
File metadata and controls
56 lines (53 loc) · 1.59 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#Get-GetActiveWindow
$code = @'
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
'@
$NonInteractiveDefaultProcesses = @(
'ApplicationFrameHost',
'backgroundTaskHost'
'CodeHelper',
'CompPkgSrv',
'ctfmon',
'dllhost',
'Docker',
'dptf_helper',
'FileCoAuth',
'gpg-agent',
'OneDrive',
'ONENOTEM',
'RemindersServer',
'RuntimeBroker',
'SCNotification'
'SearchUI',
'SearchProtocolHost',
'SettingSyncHost',
'SecurityHealthSystray',
'ShellExperienceHost',
'sihost',
'SkypeApp',
'SkypeBackgroundHost',
'SkypeBridge',
'smartscreen',
'SpeechRuntime',
'StartMenuExperienceHost',
'SurfaceDTX',
'SystemSettingsBroker',
'svchost',
'TabTip',
'taskhostw',
'vsls-agent'
'WindowsInternal.ComposableShell.Experiences.TextInput.InputApp',
'WinStore.App',
'YourPhone'
)
Add-Type $code -Name Utils -Namespace Win32
$csvPath = "C:\tracker\$(Get-Date -Format dd-MM-yy)-ActiveWindow.csv"
while (1) {
$hwnd = [Win32.Utils]::GetForegroundWindow()
Get-Process -IncludeUserName |
Where-Object { ($_.mainWindowHandle -eq $hwnd) -and ($_.userName -match $env:USERNAME) -and ($_.ProcessName -notin $NonInteractiveDefaultProcesses) } |
Select-Object processName, MainWindowTitle, MainWindowHandle, @{name = 'CurrentTime' ; expression = { [datetime]::Now.ToLongTimeString() } }, @{name = 'CurrentDate' ; expression = { [datetime]::Now.ToShortDateString() } } |
Export-Csv -Path $csvPath -Append -NoTypeInformation
Start-Sleep -Seconds 1
}