NSIS 脚本无法从 Windir 文件夹中找到文件

NSIS script not able to find the file from Windir folder

IfFileExists $windir\system32\drivers\pcitdrv.sys file_found file_not_found
file_found:
MessageBox MB_OK FileFound
file_not_found:
MessageBox MB_OK FileNotFound

此代码始终执行 file_not_found 部分代码,即使该文件存在于各自的路径中。

也试过下面的方法:

函数AB
Var /GLOBAL OnlineOrOffline
${Locate} "$windir\system32\drivers\" "/L=F /M=pcitdrv.sys" "SetOnlineOfflineVarliable"
消息框 MB_OK $OnlineOrOffline
函数结束

函数 SetOnlineOfflineVarliable
StrCpy $R0 $R9
StrCpy $OnlineOrOffline "Found"
StrCpy $0 停止定位
推动 $0
函数结束

在这种情况下也不会调用回调函数。

需要这方面的帮助。

或者干脆

我的要求是假设一台 PC 上有 $windir/system32/drivers/pcitdrv.sys 文件,而另一台 PC 上没有该文件。在安装过程中,会检查一些许可证。我们可以根据文件存在跳过许可证检查吗?

部分文件系统是 redirected,当 运行 在 32 位应用程序上,在 64 位版本的 Windows 上。

$windir\system32 被重定向到 $windir\SysWOW64.

您可以在执行检查时关闭重定向:

!include x64.nsh
Section

${DisableX64FSRedirection}
StrCpy [=10=] ""
IfFileExists "$windir\system32\drivers\pcitdrv.sys" 0 +2
StrCpy [=10=] "1"
${EnableX64FSRedirection}

StrCmp [=10=] "" 0 file_found
MessageBox MB_OK FileNotFound
goto done
file_found:
MessageBox MB_OK FileFound
done:

SectionEnd

如果您不关心 Windows XP 64 位 support,您可以使用始终访问 "real" system32 文件夹的特殊伪文件夹:

Section

IfFileExists "$windir\system32\drivers\pcitdrv.sys" file_found ; Check on 32-bit Windows
IfFileExists "$windir\sysnative\drivers\pcitdrv.sys" file_found ; Check on 64-bit Windows

MessageBox MB_OK FileNotFound
goto done
file_found:
MessageBox MB_OK FileFound
done:

SectionEnd 

其实还有一个疑问是
${DisableX64FSRedirection}
StrCpy $0 ""
IfFileExists "$windir\system32\drivers\pcitdrv.sys" 0 +2
StrCpy $0 "1"
${EnableX64FSRedirection}
StrCmp $0 "" 0 file_found
${DisableX64FSRedirection}
StrCpy $0 ""
IfFileExists "$windir\system32\drivers\tcitdrv.sys" 0 +2
StrCpy $0 "1"
${EnableX64FSRedirection}
StrCmp $0 "" 0 file_found
转到完成
file_found:

完成:
我想检查两个文件 pcit 和 tcit。
这是正确的吗?