-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadd_to_startup.ps1
More file actions
282 lines (238 loc) · 10 KB
/
add_to_startup.ps1
File metadata and controls
282 lines (238 loc) · 10 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# MouseFix Startup Configuration Script
# This script adds MouseFix to Windows startup
# Get script directory
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
# Optimized function to search for MouseFix.exe for end users
function Find-MouseFixExe {
Write-Host "Searching for MouseFix.exe..." -ForegroundColor Yellow
# Priority 1: Search in current script directory (most common for end users)
$CurrentDirPaths = @(
"$ScriptDir\MouseFix.exe",
"$ScriptDir\MouseFix\MouseFix.exe"
)
foreach ($Path in $CurrentDirPaths) {
if (Test-Path $Path) {
Write-Host "Found: $Path" -ForegroundColor Green
return $Path
}
}
# Priority 2: Search in subdirectories (for users who extracted the archive)
try {
$ExeFiles = Get-ChildItem -Path $ScriptDir -Filter "MouseFix.exe" -Recurse -Depth 2 -ErrorAction SilentlyContinue | `
Select-Object -First 3
foreach ($Exe in $ExeFiles) {
Write-Host "Found: $($Exe.FullName)" -ForegroundColor Green
return $Exe.FullName
}
} catch {
# Ignore errors during recursive search
}
# Priority 3: Search in common user directories
$UserDirs = @(
"$env:USERPROFILE\Downloads",
"$env:USERPROFILE\Desktop",
"$env:USERPROFILE\Documents",
"$env:USERPROFILE"
)
foreach ($UserDir in $UserDirs) {
if (Test-Path $UserDir) {
try {
$ExeFiles = Get-ChildItem -Path $UserDir -Filter "MouseFix.exe" -Recurse -Depth 2 -ErrorAction SilentlyContinue | `
Select-Object -First 2
foreach ($Exe in $ExeFiles) {
Write-Host "Found: $($Exe.FullName)" -ForegroundColor Green
return $Exe.FullName
}
} catch {
# Ignore errors during recursive search
}
}
}
# Priority 4: Search in parent directories (for users running script from subfolder)
try {
$ParentDir = Split-Path -Parent $ScriptDir
if ($ParentDir) {
$ExeFiles = Get-ChildItem -Path $ParentDir -Filter "MouseFix.exe" -Recurse -Depth 1 -ErrorAction SilentlyContinue | `
Select-Object -First 1
if ($ExeFiles) {
Write-Host "Found: $($ExeFiles.FullName)" -ForegroundColor Green
return $ExeFiles.FullName
}
}
} catch {
# Ignore errors during recursive search
}
return $null
}
# Search for MouseFix.exe
$MouseFixExe = Find-MouseFixExe
# If auto-search fails, prompt user for path
if (-not $MouseFixExe) {
Write-Host ""
Write-Host "=========================================" -ForegroundColor Red
Write-Host " MouseFix.exe not found" -ForegroundColor Red
Write-Host "=========================================" -ForegroundColor Red
Write-Host ""
Write-Host "The script searched the following locations:" -ForegroundColor Yellow
Write-Host " - Current script directory" -ForegroundColor Gray
Write-Host " - Subdirectories of current directory" -ForegroundColor Gray
Write-Host " - Downloads folder" -ForegroundColor Gray
Write-Host " - Desktop folder" -ForegroundColor Gray
Write-Host " - Documents folder" -ForegroundColor Gray
Write-Host ""
Write-Host "Please make sure you have downloaded MouseFix from:" -ForegroundColor Cyan
Write-Host " https://github.com/matreshka15/MouseFix/releases" -ForegroundColor Cyan
Write-Host ""
# Prompt user for path
Write-Host "Please enter the full path to MouseFix.exe (absolute path):" -ForegroundColor Cyan
Write-Host "Tip: You can drag and drop the file here" -ForegroundColor DarkGray
Write-Host ""
Write-Host "Or enter 'q' to exit the script" -ForegroundColor DarkGray
Write-Host ""
$UserPath = Read-Host "Path"
# Check if user wants to exit
if ($UserPath -eq 'q' -or $UserPath -eq 'Q') {
Write-Host ""
Write-Host "Operation cancelled" -ForegroundColor Yellow
pause
exit 0
}
# Clean path (remove quotes)
$UserPath = $UserPath.Trim('"', "'")
# Validate path
if (-not (Test-Path $UserPath)) {
Write-Host ""
Write-Host "Error: The specified path does not exist: $UserPath" -ForegroundColor Red
pause
exit 1
}
# Check if it's an .exe file
if (-not $UserPath.EndsWith('.exe', [System.StringComparison]::OrdinalIgnoreCase)) {
Write-Host ""
Write-Host "Error: The specified file is not an .exe file" -ForegroundColor Red
pause
exit 1
}
# Check if filename is MouseFix.exe
$FileName = Split-Path -Leaf $UserPath
if ($FileName -ne 'MouseFix.exe') {
Write-Host ""
Write-Host "Warning: The filename is not MouseFix.exe, current filename: $FileName" -ForegroundColor Yellow
Write-Host "Do you want to continue? (Y/N)" -ForegroundColor Yellow
$Confirm = Read-Host
if ($Confirm -ne 'Y' -and $Confirm -ne 'y') {
Write-Host ""
Write-Host "Operation cancelled" -ForegroundColor Yellow
pause
exit 0
}
}
$MouseFixExe = $UserPath
Write-Host ""
Write-Host "Using user-specified path: $MouseFixExe" -ForegroundColor Green
}
Write-Host "=========================================" -ForegroundColor Cyan
Write-Host " MouseFix Startup Configuration Tool" -ForegroundColor Cyan
Write-Host "=========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "MouseFix Path: $MouseFixExe" -ForegroundColor Green
Write-Host ""
# Provide two startup methods
Write-Host "Please select a startup method:" -ForegroundColor Yellow
Write-Host " 1. Startup Folder (Recommended - User visible, easy to manage)" -ForegroundColor White
Write-Host " 2. Registry Startup (Hidden method, system-level startup)" -ForegroundColor White
Write-Host " 3. Remove Startup" -ForegroundColor White
Write-Host " 4. Exit" -ForegroundColor White
Write-Host ""
$Choice = Read-Host "Enter option (1-4)"
switch ($Choice) {
"1" {
# Method 1: Use startup folder
Write-Host ""
Write-Host "Configuring startup folder..." -ForegroundColor Yellow
$StartupFolder = "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup"
$ShortcutPath = "$StartupFolder\MouseFix.lnk"
# Create shortcut
$WshShell = New-Object -ComObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($ShortcutPath)
$Shortcut.TargetPath = $MouseFixExe
$Shortcut.WorkingDirectory = Split-Path -Parent $MouseFixExe
$Shortcut.Description = "MouseFix - Mouse Debounce Tool"
$Shortcut.Save()
Write-Host "[OK] Successfully created startup shortcut" -ForegroundColor Green
Write-Host " Location: $ShortcutPath" -ForegroundColor Gray
Write-Host ""
Write-Host "MouseFix will start automatically on next login" -ForegroundColor Green
}
"2" {
# Method 2: Use registry
Write-Host ""
Write-Host "Configuring registry startup..." -ForegroundColor Yellow
$RegPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
$RegName = "MouseFix"
# Check if already exists
$ExistingValue = Get-ItemProperty -Path $RegPath -Name $RegName -ErrorAction SilentlyContinue
if ($ExistingValue) {
Write-Host "Found existing startup entry, updating..." -ForegroundColor Yellow
}
# Add registry entry
Set-ItemProperty -Path $RegPath -Name $RegName -Value $MouseFixExe -Force
Write-Host "[OK] Successfully added registry startup entry" -ForegroundColor Green
Write-Host " Registry Path: $RegPath" -ForegroundColor Gray
Write-Host " Key Name: $RegName" -ForegroundColor Gray
Write-Host " Value: $MouseFixExe" -ForegroundColor Gray
Write-Host ""
Write-Host "MouseFix will start automatically on next login" -ForegroundColor Green
}
"3" {
# Remove startup
Write-Host ""
Write-Host "Removing startup configuration..." -ForegroundColor Yellow
$Removed = $false
# Check startup folder
$StartupFolder = "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup"
$ShortcutPath = "$StartupFolder\MouseFix.lnk"
if (Test-Path $ShortcutPath) {
Remove-Item $ShortcutPath -Force
Write-Host "[OK] Removed startup folder shortcut" -ForegroundColor Green
$Removed = $true
}
# Check registry
$RegPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
$RegName = "MouseFix"
$ExistingValue = Get-ItemProperty -Path $RegPath -Name $RegName -ErrorAction SilentlyContinue
if ($ExistingValue) {
Remove-ItemProperty -Path $RegPath -Name $RegName -Force
Write-Host "[OK] Removed registry startup entry" -ForegroundColor Green
$Removed = $true
}
if ($Removed) {
Write-Host ""
Write-Host "Successfully removed MouseFix startup configuration" -ForegroundColor Green
} else {
Write-Host ""
Write-Host "No MouseFix startup entry found" -ForegroundColor Yellow
}
}
"4" {
Write-Host ""
Write-Host "Operation cancelled" -ForegroundColor Yellow
exit 0
}
default {
Write-Host ""
Write-Host "Invalid option" -ForegroundColor Red
pause
exit 1
}
}
Write-Host ""
Write-Host "=========================================" -ForegroundColor Cyan
Write-Host "Operation Complete!" -ForegroundColor Green
Write-Host "=========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Tips:" -ForegroundColor Yellow
Write-Host " - Press Win+R and type 'shell:startup' to open the startup folder" -ForegroundColor Gray
Write-Host " - Press Ctrl+Shift+Esc to open Task Manager, switch to 'Startup' tab to view startup items" -ForegroundColor Gray
Write-Host ""
pause