-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathInvoke-DirtyGUIHelper.ps1
More file actions
65 lines (54 loc) · 1.89 KB
/
Invoke-DirtyGUIHelper.ps1
File metadata and controls
65 lines (54 loc) · 1.89 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
57
58
59
60
61
62
63
64
65
function Invoke-DirtyGUIHelper {
<#
.Synopsis
Send ALT+Y to the specified process
.DESCRIPTION
Uses user32.dll and Windows.Forms to active a process and send the ALT+Y key combination.
.NOTES
Name : Invoke-DirtyGUIHelper.ps1
Author : Jaap Brasser
Version : 1.0
DateCreated: 2016-05-03
DateUpdated: 2016-05-03
Blog : http://www.jaapbrasser.com
.LINK
http://www.jaapbrasser.com
.EXAMPLE
. .\Invoke-DirtyGUIHelper
Description
-----------
This command dot sources the script to ensure the Invoke-DirtyGUIHelper function is available in your current PowerShell session
.EXAMPLE
Invoke-DirtyGUIHelper -ProcessName firefox
Description
-----------
Will attempt to activate the firefox windows 5 times and afterwards sending the ALT + Y combination to the program
#>
param(
[Parameter(Mandatory,
Position=0
)]
# The name of the program on which prompt ALT + Y will be send
$ProcessName
)
begin {
Add-Type -Name Win -Namespace Native -Member ('[DllImport("user32.dll")]',
'[return: MarshalAs(UnmanagedType.Bool)]',
'public static extern bool SetForegroundWindow(IntPtr hWnd);' -join "`r`n")
$Process = Get-Process $ProcessName
Add-Type -AssemblyName System.Windows.Forms
}
process {
$Count = 0
while ($($Process.Refresh();$Process.ProcessName)) {
$null = [Native.Win]::SetForegroundWindow($CleanMgrProc.MainWindowHandle)
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::Send('%Y')
Start-Sleep -Milliseconds 500
$Count++
if ($Count -eq 5) {
$Process = $null
}
}
}
}