-
Notifications
You must be signed in to change notification settings - Fork 0
/
provision-common.ps1
144 lines (131 loc) · 6.63 KB
/
provision-common.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# set keyboard layout.
# NB you can get the name from the list:
# [System.Globalization.CultureInfo]::GetCultures('InstalledWin32Cultures') | out-gridview
Set-WinUserLanguageList pt-PT -Force
# set the date format, number format, etc.
Set-Culture pt-PT
# set the timezone.
# tzutil /l lists all available timezone ids
& $env:windir\system32\tzutil /s "GMT Standard Time"
# show window content while dragging.
Set-ItemProperty -Path 'HKCU:Control Panel\Desktop' -Name DragFullWindows -Value 1
# show hidden files.
Set-ItemProperty -Path HKCU:Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name Hidden -Value 1
# show file extensions.
Set-ItemProperty -Path HKCU:Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name HideFileExt -Value 0
# display full path in the title bar.
New-Item -Path HKCU:Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState -Force `
| New-ItemProperty -Name FullPath -Value 1 -PropertyType DWORD `
| Out-Null
# set default Explorer location to This PC.
Set-ItemProperty -Path HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name LaunchTo -Value 1
# set the desktop wallpaper.
Add-Type -AssemblyName System.Drawing
$backgroundColor = [System.Drawing.Color]::FromArgb(30, 30, 30)
$backgroundPath = 'C:\Windows\Web\Wallpaper\Windows\ultravnc.png'
$logo = [System.Drawing.Image]::FromFile((Resolve-Path 'ultravnc.png'))
$b = New-Object System.Drawing.Bitmap($logo.Width, $logo.Height)
$g = [System.Drawing.Graphics]::FromImage($b)
$g.Clear($backgroundColor)
$g.DrawImage($logo, 0, 0, $logo.Width, $logo.Height)
$b.Save($backgroundPath)
Set-ItemProperty -Path 'HKCU:Control Panel\Desktop' -Name Wallpaper -Value $backgroundPath
Set-ItemProperty -Path 'HKCU:Control Panel\Desktop' -Name WallpaperStyle -Value 0
Set-ItemProperty -Path 'HKCU:Control Panel\Desktop' -Name TileWallpaper -Value 0
Set-ItemProperty -Path 'HKCU:Control Panel\Colors' -Name Background -Value ($backgroundColor.R,$backgroundColor.G,$backgroundColor.B -join ' ')
Add-Type @'
using System;
using System.Drawing;
using System.Runtime.InteropServices;
public static class WindowsWallpaper
{
private const int COLOR_DESKTOP = 0x01;
[DllImport("user32", SetLastError=true)]
private static extern bool SetSysColors(int cElements, int[] lpaElements, int[] lpaRgbValues);
private const uint SPI_SETDESKWALLPAPER = 0x14;
private const uint SPIF_UPDATEINIFILE = 0x01;
private const uint SPIF_SENDWININICHANGE = 0x02;
[DllImport("user32", SetLastError=true)]
private static extern bool SystemParametersInfo(uint uiAction, uint uiParam, string pvParam, uint fWinIni);
public static void Set(Color color, string path)
{
var elements = new int[] { COLOR_DESKTOP };
var colors = new int[] { ColorTranslator.ToWin32(color) };
SetSysColors(elements.Length, elements, colors);
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, path, SPIF_SENDWININICHANGE);
}
}
'@ -ReferencedAssemblies System.Drawing
[WindowsWallpaper]::Set($backgroundColor, $backgroundPath)
# cleanup the taskbar by removing the existing buttons and unpinning all applications; once the user logs on.
# NB the shell executes these RunOnce commands about ~10s after the user logs on.
[IO.File]::WriteAllText(
"$env:USERPROFILE\ConfigureDesktop.ps1",
@'
# unpin all applications from the taskbar.
# NB this can only be done in a logged on session.
$pinnedTaskbarPath = "$env:APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"
(New-Object -Com Shell.Application).NameSpace($pinnedTaskbarPath).Items() `
| ForEach-Object {
$unpinVerb = $_.Verbs() | Where-Object { $_.Name -eq 'Unpin from tas&kbar' }
if ($unpinVerb) {
$unpinVerb.DoIt()
} else {
$shortcut = (New-Object -Com WScript.Shell).CreateShortcut($_.Path)
if (!$shortcut.TargetPath -and ($shortcut.IconLocation -eq '%windir%\explorer.exe,0')) {
Remove-Item -Force $_.Path
}
}
}
Get-Item HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Taskband `
| Set-ItemProperty -Name Favorites -Value 0xff `
| Set-ItemProperty -Name FavoritesResolve -Value 0xff `
| Set-ItemProperty -Name FavoritesVersion -Value 3 `
| Set-ItemProperty -Name FavoritesChanges -Value 1 `
| Set-ItemProperty -Name FavoritesRemovedChanges -Value 1
# hide the search button.
Set-ItemProperty -Path HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Search -Name SearchboxTaskbarMode -Value 0
# hide the task view button.
Set-ItemProperty -Path HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name ShowTaskViewButton -Value 0
# never combine the taskbar buttons.
# possibe values:
# 0: always combine and hide labels (default)
# 1: combine when taskbar is full
# 2: never combine
Set-ItemProperty -Path HKCU:Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name TaskbarGlomLevel -Value 2
# remove default or uneeded files.
@(
"$env:USERPROFILE\Desktop\desktop.ini"
"$env:USERPROFILE\Desktop\*.lnk"
"$env:USERPROFILE\Desktop\*.url"
"$env:PUBLIC\Desktop\desktop.ini"
"$env:PUBLIC\Desktop\*.lnk"
"$env:PUBLIC\Desktop\*.url"
) | Remove-Item -Force
# execute hooks.
Import-Module C:\ProgramData\chocolatey\helpers\chocolateyInstaller.psm1
Get-ChildItem "$PSScriptRoot\ConfigureDesktop-*.ps1" `
| Sort-Object -Property Name `
| ForEach-Object { &$_ }
# restart explorer to apply the changed settings.
(Get-Process explorer).Kill()
'@)
New-Item -Path HKCU:Software\Microsoft\Windows\CurrentVersion\RunOnce -Force `
| New-ItemProperty -Name ConfigureDesktop -Value 'PowerShell -WindowStyle Hidden -File "%USERPROFILE%\ConfigureDesktop.ps1"' -PropertyType ExpandString `
| Out-Null
# install chocolatey.
iex ((New-Object Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
# install the Carbon PowerShell module.
choco install -y carbon
# install Google Chrome.
# NB --ignore-checksums is needed because chrome does not release a versioned
# installer... as such, sometimes this package installation breaks if we
# do not ignore the checksums and there's a new chrome version available.
# see https://www.chromium.org/administrators/configuring-other-preferences
choco install -y --ignore-checksums googlechrome
$chromeLocation = 'C:\Program Files (x86)\Google\Chrome\Application'
cp -Force GoogleChrome-external_extensions.json (Get-Item "$chromeLocation\*\default_apps\external_extensions.json").FullName
cp -Force GoogleChrome-master_preferences.json "$chromeLocation\master_preferences"
cp -Force GoogleChrome-master_bookmarks.html "$chromeLocation\master_bookmarks.html"
# replace notepad with notepad2.
choco install -y notepad2