From 7680422bb434144661d77e53d21edec50bd382b0 Mon Sep 17 00:00:00 2001 From: theSoberSobber Date: Sun, 3 Mar 2024 11:14:11 +0530 Subject: [PATCH] Better Path Searching and RunOnStartup --- RunOnStartup.bat | 47 +++++++++++++++++++++++++++++++++++++++++++++++ main.c | 15 +++++++-------- 2 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 RunOnStartup.bat diff --git a/RunOnStartup.bat b/RunOnStartup.bat new file mode 100644 index 0000000..e7bf11c --- /dev/null +++ b/RunOnStartup.bat @@ -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 \ No newline at end of file diff --git a/main.c b/main.c index 93b3fa1..65da786 100644 --- a/main.c +++ b/main.c @@ -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");