-
Notifications
You must be signed in to change notification settings - Fork 0
/
noshort.ps1
174 lines (159 loc) · 6.82 KB
/
noshort.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
173
174
# By nxvvvv (https://github.com/nxvvvv)
# Check if the current user is an administrator
$isAdmin = ([Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544"
if (-not $isAdmin) {
# If not an administrator, restart the script with elevated privileges
Start-Process powershell.exe -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$($MyInvocation.MyCommand.Path)`"" -Verb RunAs
}
# URL to the GitHub repository
$repositoryUrl = "https://github.com/nxvvvv/noshort"
# Display menu for the user to choose an option
Write-Host "Choose an option:"
Write-Host "1) Remove the shortcut icon"
Write-Host "2) Revert to the default shortcut icon"
Write-Host "3) Choose a custom icon"
$choice = Read-Host "Type the corresponding number (1, 2, or 3):"
# Option 1: Remove the shortcut icon
if ($choice -eq "1") {
# Set the path and URL for the default icon
$iconFilePath = "C:\Windows\blank.ico"
$iconUrl = "https://raw.githubusercontent.com/nxvvvv/noshort/files/blank.ico"
# Download the default icon
try {
Invoke-WebRequest -Uri $iconUrl -OutFile $iconFilePath -ErrorAction Stop
Write-Host "Icon file downloaded successfully!"
} catch {
Write-Host "Error downloading icon file: $_"
exit
}
# Modify registry to remove the custom icon
# Restart Windows Explorer to apply changes
Stop-Process -Name regedit -Force -ErrorAction SilentlyContinue
$regKeys = @(
"HKEY_CLASSES_ROOT\IE.AssocFile.URL",
"HKEY_CLASSES_ROOT\InternetShortcut",
"HKEY_CLASSES_ROOT\lnkfile"
)
$regKeys | ForEach-Object {
reg add $_ /v "IsShortcut" /d "" /f
}
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons" /v "29" /t REG_SZ /d "$iconFilePath" /f
taskkill /f /im explorer.exe
Start-Sleep -Seconds 2
Start-Process explorer.exe
# Display success message and open the repository URL
Write-Host "Done Successfully! Please star my repository :)"
Start-Sleep -Seconds 2
Start-Process $repositoryUrl
Start-Sleep -Seconds 5
}
# Option 2: Revert to the default shortcut icon
elseif ($choice -eq "2") {
# Set the path for the default icon
$iconFilePath = "C:\Windows\blank.ico"
# Modify registry to remove the custom icon
# Delete the registry key related to custom icon
# Remove the custom icon file
# Restart Windows Explorer to apply changes
Stop-Process -Name regedit -Force -ErrorAction SilentlyContinue
$regKeys = @(
"HKEY_CLASSES_ROOT\IE.AssocFile.URL",
"HKEY_CLASSES_ROOT\InternetShortcut",
"HKEY_CLASSES_ROOT\lnkfile"
)
$regKeys | ForEach-Object {
reg add $_ /v "IsShortcut" /d "" /f
}
$registryKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons"
if (Test-Path "Registry::$registryKey") {
reg delete $registryKey /f
}
Remove-Item -Path $iconFilePath -Force -ErrorAction SilentlyContinue
taskkill /f /im explorer.exe
Start-Sleep -Seconds 2
Start-Process explorer.exe
# Display success message and open the repository URL
Write-Host "Done Successfully! Please star my repository :)"
Start-Sleep -Seconds 2
Start-Process $repositoryUrl
Start-Sleep -Seconds 5
}
# Option 3: Choose a custom icon
elseif ($choice -eq "3") {
# Submenu for choosing an option related to custom icons
Write-Host "Choose an option:"
Write-Host "1) Select an existing icon"
Write-Host "2) Create an icon from an image file"
$iconChoice = Read-Host "Type the corresponding number (1 or 2):"
# Option 1: Select an existing icon
if ($iconChoice -eq "1") {
# Prompt user to select an existing icon file
$openFileDialog = New-Object -TypeName System.Windows.Forms.OpenFileDialog
$openFileDialog.Filter = "Icon Files (*.ico)|*.ico"
$openFileDialog.Title = "Select an icon file"
$openFileDialog.ShowDialog() | Out-Null
$inputFile = $openFileDialog.FileName
}
# Option 2: Create an icon from an image file
elseif ($iconChoice -eq "2") {
# Prompt user to select an image file
$openFileDialog = New-Object -TypeName System.Windows.Forms.OpenFileDialog
$openFileDialog.Filter = "Image Files (*.jpg;*.jpeg;*.png;*.gif)|*.jpg;*.jpeg;*.png;*.gif"
$openFileDialog.Title = "Select an image file"
$openFileDialog.ShowDialog() | Out-Null
$inputFile = $openFileDialog.FileName
# Create necessary directories if they don't exist
if (-not (Test-Path "C:\noshort")) {
New-Item -ItemType Directory -Path "C:\noshort" | Out-Null
}
if (-not (Test-Path "C:\noshort\ico")) {
New-Item -ItemType Directory -Path "C:\noshort\ico" | Out-Null
}
if (-not (Test-Path "C:\noshort\converter")) {
New-Item -ItemType Directory -Path "C:\noshort\converter" | Out-Null
}
# Define output file path and URLs for custom icon creation
$outputFile = "C:\noshort\ico\" + [System.IO.Path]::GetFileNameWithoutExtension($inputFile) + ".ico"
$customExePath = "C:\noshort\converter\custom.exe"
$customExeUrl = "https://github.com/nxvvvv/noshort/raw/files/custom.exe"
# Download custom converter tool if not present
if (-not (Test-Path $customExePath)) {
Write-Host "Getting converter..."
try {
Invoke-WebRequest -Uri $customExeUrl -OutFile $customExePath -ErrorAction Stop
Write-Host "Success!"
} catch {
Write-Host "Error getting converter!?!?"
exit
}
}
# Execute custom converter tool to create the icon
$arguments = """$inputFile"" ""$outputFile"""
Start-Process -FilePath $customExePath -ArgumentList $arguments -Wait
}
# Modify registry to set the custom icon
# Restart Windows Explorer to apply changes
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons" /v "29" /t REG_SZ /d "$outputFile" /f
Stop-Process -Name regedit -Force -ErrorAction SilentlyContinue
$regKeys = @(
"HKEY_CLASSES_ROOT\IE.AssocFile.URL",
"HKEY_CLASSES_ROOT\InternetShortcut",
"HKEY_CLASSES_ROOT\lnkfile"
)
$regKeys | ForEach-Object {
reg add $_ /v "IsShortcut" /d "" /f
}
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons" /v "29" /t REG_SZ /d "$outputFile" /f
taskkill /f /im explorer.exe
Start-Sleep -Seconds 2
Start-Process explorer.exe
# Display success message and open the repository URL
Write-Host "Done Successfully! Please star my repository :)"
Start-Sleep -Seconds 2
Start-Process $repositoryUrl
Start-Sleep -Seconds 5
}
# Invalid choice
else {
Write-Host "Invalid choice. Exiting script."
}