-
Notifications
You must be signed in to change notification settings - Fork 1
/
RunOnStartup.bat
47 lines (37 loc) · 1.33 KB
/
RunOnStartup.bat
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
@echo off
REM Check if running with administrative privileges
net session >nul 2>&1
if %errorlevel% neq 0 (
echo This script requires administrative privileges. Please run this script as an administrator.
pause
exit /b 1
)
REM Prompt the user to enter the name of the executable
set /p exeName=Enter the name of the executable (without extension):
REM Get the absolute path of the directory where this script is located
for %%i in ("%~dp0.") do set "scriptDir=%%~fi"
REM Create the full path to the executable
set "exePath=%scriptDir%\%exeName%.exe"
echo User Input Executable Path: %exePath%
REM Check if the executable exists
if not exist "%exePath%" (
echo Error: The specified executable does not exist.
pause
exit /b 1
)
REM Create the registry entry for startup
set "registryKey=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run"
set "registryValue=sxhkd-win32"
set "registryData=%scriptDir%\%exeName%.exe"
echo Adding Registry Key %registryKey%\%registryValue% with value as %registryData%
REM Add the registry entry
reg add "%registryKey%" /v "%registryValue%" /t REG_SZ /d "%registryData%" /f >nul
REM Check if the registry entry was added successfully
if %errorlevel% neq 0 (
echo Error: Failed to add the registry entry.
pause
exit /b 1
)
echo Startup entry added successfully.
pause
exit /b