【问题标题】:NSIS script not able to find the file from Windir folderNSIS 脚本无法从 Windir 文件夹中找到文件
【发布时间】:2017-02-08 12:34:14
【问题描述】:

IfFileExists $windir\system32\drivers\pcitdrv.sys file_found file_not_found
file_found:
MessageBox MB_OK FileFound
文件未找到:
MessageBox MB_OK FileNotFound

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

还尝试了以下方法:

功能 AB
Var /GLOBAL 在线或离线
${Locate} "$windir\system32\drivers\" "/L=F /M=pcitdrv.sys" "SetOnlineOfflineVarliable"
消息框 MB_OK $OnlineOrOffline
功能结束

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

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

需要这方面的帮助。

或者干脆

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

【问题讨论】:

  • 这只发生在 64 位 Windows 上吗?

标签: nsis


【解决方案1】:

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

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

检查时可以关闭重定向:

!include x64.nsh
Section

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

StrCmp $0 "" 0 file_found
MessageBox MB_OK FileNotFound
goto done
file_found:
MessageBox MB_OK FileFound
done:

SectionEnd

如果您不关心 Windows XP 64 位 support,您可以使用始终访问“真实”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 

【讨论】:

  • 谢谢。有用。但是那个 0 +2 有什么作用。这个脚本也适用于所有位版本吗?也喜欢 32/64
  • 0 是不跳转,+2 是跳过这条和下一条指令。应该在任何地方工作。
  • 哦!谢谢安德斯。
【解决方案2】:

其实还有一个疑问
${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
完成
找到的文件:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-16
    • 1970-01-01
    • 1970-01-01
    • 2019-07-28
    相关资源
    最近更新 更多