-
Notifications
You must be signed in to change notification settings - Fork 2
/
Software-Installer.ps1
129 lines (110 loc) · 5.18 KB
/
Software-Installer.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
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
#---------------------------------------------------------[Initialisations]--------------------------------------------------------
$SoftwareList = Import-Csv -Path '.\SoftwareList.csv' -Delimiter ';' -Encoding 'UTF8'
[hashtable]$AppSelection = @{}
[hashtable]$AppSize = @{}
$SizeSum = 0
$ApplicationTitle = "Software Installer"
$ButtonBackgroundColor = "#003F9A"
$FormBackgroundColor = "#468FEA"
$FormForegroundColor = "#FFFFFF"
$MarginSize = 25
$NumberOfColumns = 3
$CheckboxWidth = 200
$ComboBoxHeight = 25
$ColumnWidth = 200
$TextBoxHeight = 150
$ProgressBarHeight = 25
$ButtonWidth = 120
$ButtonHeight = 35
if ($SoftwareList.Count % $NumberOfColumns -gt 0) {
$NumberOfRows = ($SoftwareList.Count / $NumberOfColumns) + 1
}
else {
$NumberOfRows = $SoftwareList.Count / $NumberOfColumns
}
$ComboBoxBlockWidth = $NumberOfColumns * $ColumnWidth
$ComboBoxBlockHeight = $NumberOfRows * $ComboBoxHeight
$MainFormWidth = $ComboBoxBlockWidth + ($MarginSize * 2)
$MainFormHeight = $ComboBoxBlockHeight + $TextBoxHeight + $ProgressBarHeight + $ButtonHeight + ($MarginSize * 4)
$TextBoxPosition = $ComboBoxBlockHeight + $MarginSize
$ProgressBarPosition = $TextBoxPosition + $MarginSize + $TextBoxHeight
$ButtonPosition = $ProgressBarPosition + $MarginSize + $ProgressBarHeight
#-----------------------------------------------------------[Functions]------------------------------------------------------------
#-----------------------------------------------------------[Execution]------------------------------------------------------------
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$MainForm = New-Object system.Windows.Forms.Form
$MainForm.ClientSize = New-Object System.Drawing.Point($MainFormWidth, $MainFormHeight)
$MainForm.Text = $ApplicationTitle
$MainForm.TopMost = $true
$MainForm.FormBorderStyle = 'Fixed3D'
$MainForm.MaximizeBox = $false
$MainForm.ShowIcon = $false
$MainForm.BackColor = $FormBackgroundColor
$MainForm.ForeColor = $FormForegroundColor
$XAxisCheckbox = $MarginSize
$YAxisCheckbox = $MarginSize
$ColumnCounter = 1
foreach ($Application in $SoftwareList) {
$SoftwareCheckbox = New-Object System.Windows.Forms.CheckBox
$SoftwareCheckbox.AutoSize = $false
$SoftwareCheckbox.Size = New-Object System.Drawing.Size($CheckboxWidth, $ComboBoxHeight)
$SoftwareCheckbox.Location = New-Object System.Drawing.Size($XAxisCheckbox, $YAxisCheckbox)
$SoftwareCheckbox.Text = $Application.Name
$SoftwareCheckbox.Checked = $false
$SoftwareCheckbox.Font = New-Object System.Drawing.Font('Microsoft Sans Serif', 10, [System.Drawing.FontStyle]([System.Drawing.FontStyle]::Bold))
$MainForm.controls.Add($SoftwareCheckbox)
$Size = (Get-Item -Path $Application.Path).Length
$AppSize.Add($Application.Name, $Size)
if ($ColumnCounter -lt $NumberOfColumns) {
$XAxisCheckbox += $ColumnWidth
$ColumnCounter += 1
}
else {
$XAxisCheckbox = $MarginSize
$YAxisCheckbox += $ComboBoxHeight
$ColumnCounter = 1
}
$AppSelection.Add($Application.Name, $SoftwareCheckbox)
}
$TextBox = New-Object System.Windows.Forms.TextBox
$TextBox.Location = New-Object System.Drawing.Point($MarginSize, $TextBoxPosition)
$TextBox.Size = New-Object System.Drawing.Size($ComboBoxBlockWidth, $TextBoxHeight)
$TextBox.AutoSize = $false
$TextBox.Multiline = $true
$TextBox.Scrollbars = "Vertical"
$TextBox.ReadOnly = $true
$MainForm.Controls.Add($TextBox)
$ProgressBar = New-Object System.Windows.Forms.ProgressBar
$ProgressBar.Location = New-Object System.Drawing.Point($MarginSize, $ProgressBarPosition)
$ProgressBar.Size = New-Object System.Drawing.Size($ComboBoxBlockWidth, $ProgressBarHeight)
$ProgressBar.Style = "Continuous"
$ProgressBar.MarqueeAnimationSpeed
$MainForm.Controls.Add($ProgressBar)
$InstallButton = New-Object system.Windows.Forms.Button
$InstallButton.Text = "Install"
$InstallButton.Width = $ButtonWidth
$InstallButton.Height = $ButtonHeight
$InstallButton.Location = New-Object System.Drawing.Point((($MainFormWidth - $ButtonWidth) / 2), $ButtonPosition)
$InstallButton.Font = New-Object System.Drawing.Font('Microsoft Sans Serif', 10, [System.Drawing.FontStyle]([System.Drawing.FontStyle]::Bold))
$InstallButton.BackColor = $ButtonBackgroundColor
$MainForm.controls.Add($InstallButton)
$InstallButton.Add_Click({
$TextBox.Text += "Software installation starting . . .`r`n"
foreach ($Application in $SoftwareList) {
if ($AppSelection[$Application.Name].Checked) {
$SizeSum += $AppSize[$Application.Name]
}
}
foreach ($Application in $SoftwareList) {
if ($AppSelection[$Application.Name].Checked) {
$TextBox.Text += ("Installing " + $Application.Name + " . . .`r`n")
$ProgressBar.Capture
$ProgressBar.Value += ($AppSize[$Application.Name] / $SizeSum) * 100
Start-Process -FilePath $Application.Path -ArgumentList $Application.Arguments -PassThru | Wait-Process
$TextBox.Text += ($Application.Name + " application installed`r`n")
}
}
$TextBox.Text += "Software installation completed`r`n"
})
[void]$MainForm.ShowDialog()