: nply/dwhkd

commit 7680422bb434144661d77e53d21edec50bd382b0
parent 060eb5bcd8ae2ce04664aa6c56720f87302fd75a
Author: theSoberSobber <akshatshrivastava0010@gmail.com>
Date: Sun, 3 Mar 2024 11:14:11 +0530

Better Path Searching and RunOnStartup
2 files changed, 55 insertions(+), 8 deletions(-)
A
RunOnStartup.bat
|
48
++++++++++++++++++++++++++++++++++++++++++++++++
M
main.c
|
15
+++++++--------
diff --git a/RunOnStartup.bat 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
@@ -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");