-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOne-Button-Gui-Macro.ps1
More file actions
150 lines (128 loc) · 4.37 KB
/
Copy pathOne-Button-Gui-Macro.ps1
File metadata and controls
150 lines (128 loc) · 4.37 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#parts borrowed from unknown places on the web, but keystroke sending part is mine. Gui created using visual studio WPF forms.
#Simple script that creates a gui that when pressed, activates a window and sends keystrokes to said window.
#Your XAML goes here :)
$inputXML = @"
<Window x:Name="The_900" x:Class="The_900.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:The_900"
mc:Ignorable="d"
Title="The 900" Height="199.864" Width="179363">
<Grid>
<Button x:Name="the900" Content="900 the user" HorizontalAlignment="Left" Margin="26,40,0,0" VerticalAlignment="Top" Width="115" Height="90"/>
</Grid>
</Window>
"@
$inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window'
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
[xml]$XAML = $inputXML
#Read XAML
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
try{
$Form=[Windows.Markup.XamlReader]::Load( $reader )
}
catch{
Write-Warning "Unable to parse XML, with error: $($Error[0])`n Ensure that there are NO SelectionChanged or TextChanged properties in your textboxes (PowerShell cannot process them)"
throw
}
#===========================================================================
# Load XAML Objects In PowerShell
#===========================================================================
$xaml.SelectNodes("//*[@Name]") | %{"trying item $($_.Name)";
try {Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name) -ErrorAction Stop}
catch{throw}
}
Function Get-FormVariables{
if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
get-variable WPF*
}
Get-FormVariables
#===========================================================================
# Use this space to add code to the various form elements in your GUI
#===========================================================================
#Reference
#Adding items to a dropdown/combo box
#$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
#Setting the text of a text box to the current PC name
#$WPFtextBox.Text = $env:COMPUTERNAME
#Adding code to a button, so that when clicked, it pings a system
# $WPFbutton.Add_Click({ Test-connection -count 1 -ComputerName $WPFtextBox.Text
# })
#===========================================================================
# Shows the form
#===========================================================================
write-host "To show the form, run the following" -ForegroundColor Cyan
'$Form.ShowDialog() | out-null'
$WPFthe900.Add_Click({
$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('Application Window Name goes here')
Sleep 1
Sleep .5
$wshell.SendKeys("{down}")
Sleep .5
$wshell.SendKeys("{down}")
Sleep .5
$wshell.SendKeys("{down}")
Sleep .5
$wshell.SendKeys("{down}")
Sleep .5
$wshell.SendKeys("{down}")
Sleep .5
$wshell.SendKeys("{down}")
Sleep .5
$wshell.SendKeys("{down}")
Sleep .5
$wshell.SendKeys("{down}")
Sleep .5
$wshell.SendKeys("{down}")
Sleep .5
$wshell.SendKeys("{down}")
Sleep .5
$wshell.SendKeys("{down}")
Sleep .5
$wshell.SendKeys("{down}")
Sleep .5
$wshell.SendKeys("n")
Sleep .5
$wshell.SendKeys("{ENTER}")
Sleep .5
$wshell.SendKeys("{down}")
Sleep .5
$wshell.SendKeys("900")
Sleep .5
$wshell.SendKeys("{down}")
Sleep .5
$wshell.SendKeys("{down}")
Sleep .5
$wshell.SendKeys("{down}")
Sleep .5
$wshell.SendKeys("{down}")
Sleep .5
$wshell.SendKeys("{down}")
Sleep .5
$wshell.SendKeys("{down}")
Sleep .5
$wshell.SendKeys("{down}")
Sleep .5
$wshell.SendKeys("{down}")
Sleep .5
$wshell.SendKeys("{down}")
Sleep .5
$wshell.SendKeys("{down}")
Sleep .5
$wshell.SendKeys("s")
Sleep .5
$wshell.SendKeys("{ENTER}")
Sleep .5
$wshell.SendKeys("ex")
Sleep .5
$wshell.SendKeys("{ENTER}")
Sleep 1
$wshell.SendKeys("ed")
Sleep .5
$wshell.SendKeys("{ENTER}")
})
$Form.ShowDialog() | out-null