Skip to content

Commit

Permalink
Better Path Searching and RunOnStartup
Browse files Browse the repository at this point in the history
  • Loading branch information
theSoberSobber committed Mar 3, 2024
1 parent 060eb5b commit 7680422
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
47 changes: 47 additions & 0 deletions RunOnStartup.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
15 changes: 7 additions & 8 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,13 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
dbg("Hello!! : ))\n");
#ifdef VDA_FEATURES
char* libName = "\\VirtualDesktopAccessor.dll";
TCHAR libFullPath[MAX_PATH + 1] = { 0 };
GetCurrentDirectory(MAX_PATH, libFullPath);
// for(int i=0; libFullPath[i]; i++) if(libFullPath[i]=='\\') libFullPath[i]='/';
strcat_s(libFullPath, sizeof libFullPath, libName);
VDA = LoadLibrary(libFullPath);
if (VDA == NULL){
printf("Failed to load the DLL, VD Features will not work");
};
TCHAR exeFullPath[MAX_PATH + 1] = { 0 };
GetModuleFileName(NULL, exeFullPath, MAX_PATH);
char* lastSlash = strrchr(exeFullPath, '\\');
if (lastSlash != NULL) *(lastSlash + 1) = '\0';
strcat_s(exeFullPath, sizeof exeFullPath, libName);
HINSTANCE VDA = LoadLibrary(exeFullPath);
if (VDA == NULL) printf("Failed to load the DLL, VD Features will not work\n");
MoveWindowToDesktopNumberFunc = (MoveWindowToDesktopNumber)GetProcAddress(VDA, "MoveWindowToDesktopNumber");
GoToDesktopNumberFunc = (GoToDesktopNumber)GetProcAddress(VDA, "GoToDesktopNumber");
GetCurrentDesktopFunc = (GetCurrentDesktop)GetProcAddress(VDA, "GetCurrentDesktopNumber");
Expand Down

0 comments on commit 7680422

Please sign in to comment.