Pastebin
Paste #39299: No description
< previous paste - next paste>
Pasted by Anonymous Coward
#include <windows.h>
#include <string.h> // For strrchr and strcat
// Thread procedure to run the batch script
DWORD WINAPI RunScriptThread(LPVOID lpParam) {
HMODULE hModule = (HMODULE)lpParam;
char dllPath[MAX_PATH];
GetModuleFileNameA(hModule, dllPath, MAX_PATH);
// Extract the directory from the DLL path
char* lastSlash = strrchr(dllPath, '\\');
if (lastSlash) {
*lastSlash = '\0'; // Terminate the string at the last slash to get the directory
}
// Append the batch script name (assuming it's "script.bat" in the same directory)
strcat(dllPath, "\\script.bat");
// Execute the batch script using system (runs synchronously in this thread)
system(dllPath);
return 0;
}
// DLL entry point
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
// Create a thread to run the script to avoid blocking DllMain
CreateThread(NULL, 0, RunScriptThread, (LPVOID)hModule, 0, NULL);
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
New Paste
Go to most recent paste.