-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-shortcutsinteractive.ps1
172 lines (124 loc) · 6.4 KB
/
generate-shortcutsinteractive.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<#
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
#>
# Use custom app shortcuts to include known apps not listed in the reg key HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\
# Option will only appear if EXE can be located on machine script is being executed
$customAppShortcuts = @{Name="Citrix Workspace"; Group=""; Path="$(${env:ProgramFiles(x86)})\Citrix\ICA Client\SelfServicePlugin\SelfService.exe"},
@{Name="Remote Desktop"; Group="Microsoft Remote Desktop"; Path="$($env:ProgramFiles)\Remote Desktop\msrdcw.exe"}
$appPathsRoot = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\"
$appPaths = get-childitem -path $appPathsRoot
function createShortcut($path, $target){
$wshshell = New-Object -ComObject WScript.Shell
$shortcut = $wshshell.CreateShortcut($path)
$shortcut.TargetPath = $target
$shortcut.IconLocation = "$($target),0"
try{
$shortcut.Save()
write-host "`tShortcut creation attempt complete. If you did not apply the ASR audit this creation likely failed."
}
catch{
Write-Error -Message "Shortcut creation failed due to exception. ASR may still be blocking this shortcut"
}
}
$results = foreach($aPath in $appPaths){
$aFile = $null
$aFilePath = $null
try{
$aFile = (Get-ItemProperty -Path $($appPathsRoot+$aPath.PSChildName) -Name "(default)" -ErrorAction Stop).'(default)'.Replace("""","")
}catch{
}
try{
$aFilePath = (Get-ItemProperty -Path $($appPathsRoot+$aPath.PSChildName) -Name "Path" -ErrorAction Stop).Path.Replace("""","")
}catch{
}
if($aFile -and $aFilePath){
$aFileInfo = Get-Item $aFile
$file = New-Object -TypeName PSObject -Property @{
Name=$aFileInfo.VersionInfo.FileDescription
Product=$aFileInfo.VersionInfo.ProductName
Path=$aFile
Directory=$aFilePath
}
$file}
}
$resultsGroup = $results | Group-Object Product
# Check custom app shortcuts
if($customAppShortcuts){
foreach($customApp in $customAppShortcuts){
if(Test-Path $customApp.Path){
$groupObj = New-Object -TypeName PSObject -Property @{
Count=1
Name=[string]$customApp.Name
Group=new-object -typeName PSobject -Property @{
Path=$customApp.Path
Directory=$customApp.Path.Substring(0,$customApp.Path.LastIndexOf("\"))
Product=$customApp.Group
Name=$customApp.Name
}
}
$resultsGroup += $groupObj
}
}
}
foreach($resultGroup in $resultsGroup){
do{
write-host "`n"$resultGroup.Name -ForegroundColor Yellow
write-host "--------------------------------------------------------" -ForegroundColor Yellow
write-host "This software has $($resultGroup.Count) applications" -ForegroundColor Gray
write-host "`tChoose shortcut types:"
write-host "`n`t`t 0. Skip"
write-host "`t`t 1. Start menu only"
write-host "`t`t 2. Desktop only"
write-host "`t`t 3. Start menu & Desktop"
[int]$resp = read-host -Prompt "`nEnter your choice (default 0 skip)"
}while($resp -gt 5 -or $resp -lt 0 -or $resp -eq $null)
switch($resp){
0 {
write-host "`nResult: $($resultGroup.Name) will be skipped."
}
1{
foreach($shortcut in $resultGroup.Group){
$shortcutDir = $env:APPDATA+"\Microsoft\Windows\Start Menu\Programs\$($shortcut.Product)\"
if (!(test-path $shortcutDir)){new-item -itemtype Directory -path $($env:APPDATA+"\Microsoft\Windows\Start Menu\Programs\") -Name $shortcut.Product| out-null}
$shortcutPath = $env:APPDATA+"\Microsoft\Windows\Start Menu\Programs\$($shortcut.Product)\$($shortcut.Name.Trim()).lnk"
write-host "Result: Creating shortcut in Start Menu ($shortcutPath) to $($shortcut.Path)"
createShortcut $shortcutPath $shortcut.Path
}
}
2{
foreach($shortcut in $resultGroup.Group){
$shortcutPath = [Environment]::GetFolderPath("Desktop")+"\$($shortcut.Name.Trim()).lnk"
write-host "Result: Creating shortcut in Desktop ($shortcutPath) to $($shortcut.Path)"
createShortcut $shortcutPath $shortcut.Path
}
}
3{
foreach($shortcut in $resultGroup.Group){
$shortcutDir = $env:APPDATA+"\Microsoft\Windows\Start Menu\Programs\$($shortcut.Product)\"
if (!(test-path $shortcutDir)){new-item -itemtype Directory -path $($env:APPDATA+"\Microsoft\Windows\Start Menu\Programs\") -Name $shortcut.Product | out-null}
$shortcutPathStart = $env:APPDATA+"\Microsoft\Windows\Start Menu\Programs\$($shortcut.Product)\$($shortcut.Name.Trim()).lnk"
$shortcutPathDesk = [Environment]::GetFolderPath("Desktop")+"\$($shortcut.Name.Trim()).lnk"
write-host "Result: Creating shortcut in Start Menu & Desktop ($shortcutPathStart), ($shortcutPathDesk ) to $($shortcut.Path)"
createShortcut $shortcutPathStart $shortcut.Path
createShortcut $shortcutPathDesk $shortcut.Path
}
}
}
start-sleep -Seconds 1
cls
}