Remove current working directory from DLL search

Global setting

The CWDIllegalInDllSearch registry entry can be used to remove the current working directory (CWD) from the DLL search order. I highly recommend setting this registry entry as it protects from DLL hijacking attacks:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager]
"CWDIllegalInDLLSearch"=dword:ffffffff
global.reg

Exceptions for specific applications

Some applications do not work properly when the CWDIllegalInDllSearch registry entry is used. Such applications typically do not even start and might silently terminate without any error message.

Fortunately, you can use application-specific settings which take precedence over the global setting. I know of the following applications that require such a setting:

Plants vs. Zombies

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\popcapgame1.exe]
"CWDIllegalInDllSearch"=dword:00000002
plants-zombies.reg

Age of Empires II: The Conquerors

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\age2_x1.Exe]
"CWDIllegalInDllSearch"=dword:00000002
aoc.reg