NSIS系统kernel32 :: LoadLibrary不搜索Outdir或Path

时间:2017-08-08 11:47:44

标签: nsis

我正在尝试在我的NSIS安装程序中加载并调用C库DLL的函数。当我尝试加载DLL时,会发出错误126(ERROR_MOD_NOT_FOUND)。

这是我用来测试它的最小安装程序脚本:

OutFile Main.exe

ShowInstDetails show

Section
  SetOutPath "C:\Program Files (x86)\MyApp"
  System::Call 'kernel32::LoadLibraryA(m "C:\Program Files (x86)\MyApp\API.dll")i.r0 ? e'
  Pop $9
  DetailPrint $9
  DetailPrint $0

  System::Call 'kernel32::GetProcAddress(i r0,m "GetVersion")i.r1 ? e'
  Pop $9
  DetailPrint $9
  DetailPrint $1
  System::Call 'kernel32::FreeLibrary(ir0)'
SectionEnd

你可以看到我正在设置我的outpath到DLL所在的位置;所有依赖项都在哪里。但是,在检查procmon中的进程时,我看到只搜索Windows系统目录中的依赖项,而不是outpath:

Load Image             C:\Program Files (x86)\MyApp\API.dll  SUCCESS                 
CreateFile             C:\Program Files (x86)\MyApp\API.dll  SUCCESS                 
QueryBasicInformationFiC:\Program Files (x86)\MyApp\API.dll  SUCCESS                 
CloseFile              C:\Program Files (x86)\MyApp\API.dll  SUCCESS                 
CloseFile              C:\Program Files (x86)\MyApp\API.dll  SUCCESS                 
Thread Create                                                SUCCESS                 
CreateFile             C:\Windows\syswow64\DEPENDENCY_1.dll  NAME NOT FOUND          
CreateFile             C:\Windows\syswow64\msvcr100.dll      SUCCESS                 
QueryBasicInformationFiC:\Windows\syswow64\msvcr100.dll      SUCCESS                 
CloseFile              C:\Windows\syswow64\msvcr100.dll      SUCCESS                 
CreateFile             C:\Windows\syswow64\DEPENDENCY_2.dll  NAME NOT FOUND          
CreateFile             C:\Windows\syswow64\DEPENDENCY_3.dll  NAME NOT FOUND          
CreateFile             C:\Windows\syswow64\msvcr100.dll      SUCCESS                 

如何让我的outpath被搜索依赖?应该注意“C:\ Program Files(x86)\ MyApp”也在Path环境变量中,为什么不进行搜索?

1 个答案:

答案 0 :(得分:0)

NSIS中的最新安全更改已锁定了允许您从中加载库的位置。您可以致电AddDllDirectory添加其他目录:

Section
System::Call 'KERNEL32::AddDllDirectory(w "c:\path")' ; Note: Path must exist at this point
System::Call 'KERNEL32::LoadLibrary(t "c:\path\file.dll")p.r0'
System::Call 'KERNEL32::GetProcAddress(pr0, m "somefunction")p.r1'
${If} $1 P<> 0
  ...
${EndIf}
System::Call 'KERNEL32::FreeLibrary(pr0)'
SectionEnd