| 1 | @echo off |
| 2 | setlocal enabledelayedexpansion |
| 3 | |
| 4 | echo PATH=%PATH% |
| 5 | |
| 6 | if "%~1"=="" ( |
| 7 | echo Error: Missing .mc file path. |
| 8 | goto :usage |
| 9 | ) |
| 10 | if "%~2"=="" ( |
| 11 | echo Error: Missing destination directory. |
| 12 | goto :usage |
| 13 | ) |
| 14 | |
| 15 | REM Set variables |
| 16 | set "SRC_DIR=%~1" |
| 17 | set "BIN_DIR=%~2" |
| 18 | set "MC_FILE=%BIN_DIR%\wevt_netdata.mc" |
| 19 | set "MAN_FILE=%BIN_DIR%\wevt_netdata_manifest.xml" |
| 20 | set "BASE_NAME=wevt_netdata" |
| 21 | set "SDK_PATH=C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64" |
| 22 | set "VS_PATH=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\bin\Hostx64\x64" |
| 23 | |
| 24 | if not exist "%SRC_DIR%" ( |
| 25 | echo Error: Source directory does not exist. |
| 26 | exit /b 1 |
| 27 | ) |
| 28 | |
| 29 | if not exist "%BIN_DIR%" ( |
| 30 | echo Error: Destination directory does not exist. |
| 31 | exit /b 1 |
| 32 | ) |
| 33 | |
| 34 | if not exist "%MC_FILE%" ( |
| 35 | echo Error: %MC_FILE% not found. |
| 36 | exit /b 1 |
| 37 | ) |
| 38 | |
| 39 | if not exist "%MAN_FILE%" ( |
| 40 | echo Error: %MAN_FILE% not found. |
| 41 | exit /b 1 |
| 42 | ) |
| 43 | |
| 44 | REM Add SDK paths to PATH |
| 45 | set "PATH=C:\Windows\System32;%SDK_PATH%;%VS_PATH%;%PATH%" |
| 46 | |
| 47 | REM Check if commands are available |
| 48 | where mc >nul 2>nul |
| 49 | if %errorlevel% neq 0 ( |
| 50 | echo Error: mc.exe not found in PATH. |
| 51 | exit /b 1 |
| 52 | ) |
| 53 | where rc >nul 2>nul |
| 54 | if %errorlevel% neq 0 ( |
| 55 | echo Error: rc.exe not found in PATH. |
| 56 | exit /b 1 |
| 57 | ) |
| 58 | where link >nul 2>nul |
| 59 | if %errorlevel% neq 0 ( |
| 60 | echo Error: link.exe not found in PATH. |
| 61 | exit /b 1 |
| 62 | ) |
| 63 | where wevtutil >nul 2>nul |
| 64 | if %errorlevel% neq 0 ( |
| 65 | echo Error: wevtutil.exe not found in PATH. |
| 66 | exit /b 1 |
| 67 | ) |
| 68 | |
| 69 | REM Change to the destination directory |
| 70 | cd /d "%BIN_DIR%" |
| 71 | |
| 72 | echo. |
| 73 | echo Running mc.exe... |
| 74 | mc -v -b -U "%MC_FILE%" "%MAN_FILE%" |
| 75 | if %errorlevel% neq 0 ( |
| 76 | echo Error: mc.exe failed on messages. |
| 77 | exit /b 1 |
| 78 | ) |
| 79 | |
| 80 | if not exist "%BASE_NAME%.rc" ( |
| 81 | echo Error: %BASE_NAME%.rc not found. |
| 82 | exit /b 1 |
| 83 | ) |
| 84 | |
| 85 | echo. |
| 86 | echo Modifying %BASE_NAME%.rc to include the manifest... |
| 87 | copy "%MAN_FILE%" %BASE_NAME%_manifest.man |
| 88 | echo 1 2004 "%BASE_NAME%_manifest.man" >> %BASE_NAME%.rc |
| 89 | |
| 90 | echo. |
| 91 | echo %BASE_NAME%.rc contents: |
| 92 | type %BASE_NAME%.rc |
| 93 | |
| 94 | echo. |
| 95 | echo Running rc.exe... |
| 96 | rc /v /fo %BASE_NAME%.res %BASE_NAME%.rc |
| 97 | if %errorlevel% neq 0 ( |
| 98 | echo Error: rc.exe failed. |
| 99 | exit /b 1 |
| 100 | ) |
| 101 | |
| 102 | if not exist "%BASE_NAME%.res" ( |
| 103 | echo Error: %BASE_NAME%.res not found. |
| 104 | exit /b 1 |
| 105 | ) |
| 106 | |
| 107 | echo. |
| 108 | echo Running link.exe... |
| 109 | link /dll /noentry /machine:x64 /out:%BASE_NAME%.dll %BASE_NAME%.res |
| 110 | if %errorlevel% neq 0 ( |
| 111 | echo Error: link.exe failed. |
| 112 | exit /b 1 |
| 113 | ) |
| 114 | |
| 115 | echo. |
| 116 | echo Process completed successfully. |
| 117 | exit /b 0 |
| 118 | |
| 119 | :usage |
| 120 | echo Usage: %~nx0 [path_to_mc_file] [destination_directory] |
| 121 | exit /b 1 |