echo off

REM get batch file path including final backslash and append wtkjni.dll
SET BatchDir=%~dp0
SET wtkjniPath=%BatchDir%wtkjni.dll

REM only install if the config file doesn't exist
if exist %BatchDir%wtkjni.cfg (
    REM already installed
    exit /b
)

REM registry key that supports AppInit_DLLs value
set KEY="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows"

REM backup AppInit_DLLs related values
reg export %KEY% %BatchDir%AppInit_DLLs_Backup.reg

REM add wtkjni.dll to AppInit_DLLs registry value
reg add %KEY% /f /v "AppInit_DLLs" /t REG_SZ /d %wtkjniPath%

REM enable AppInit_DLLs feature
reg add %KEY% /f /v "LoadAppInit_DLLs" /t REG_DWORD /d 00000001

REM disable requirement for signed AppInit_DLLs
REM on some Windows versions, the value may be slightly different
reg query %KEY% /v "RequiresSignedAppInit_DLLs"
REM reg query returns 0 if the value exists, so we change its content
if %ERRORLEVEL% EQU 0 (
    reg add %KEY% /f /v "RequiresSignedAppInit_DLLs" /t REG_DWORD /d 00000000
)

reg query %KEY% /v "RequireSignedAppInit_DLLs"
REM reg query returns 0 if the value exists, so we change its content
if %ERRORLEVEL% EQU 0 (
    reg add %KEY% /f /v "RequireSignedAppInit_DLLs" /t REG_DWORD /d 00000000
)

REM add sample entries to wtkjni.cfg. Note that the config entry format is:
REM executable name or path
REM e.g. HelloWorld.exe
REM      c:\some\directory\HelloWorld.exe
REM similar entries can be added for specific applications of interest, one per line.
echo Example1.exe> wtkjni.cfg
echo c:\some\directory\Example2.exe>> wtkjni.cfg


