使用NSIS检测目标卷是否为NTFS [英] Detecting if the target volume is NTFS using NSIS

查看:80
本文介绍了使用NSIS检测目标卷是否为NTFS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NSIS创建一个需要在NTFS卷上运行的程序的安装程序.如何检测路径安装是否在NTFS卷上并采取相应措施(显示帮助/警告消息)?

I'm creating an installer with NSIS for a program that needs to run on an NTFS volume. How do I detect if the install to path is on an NTFS volume and act accordingly (show a help/warning message)?

推荐答案

使用外部工具并不总是一个好主意(并非Windows Home版本的Windows中都存在每个命令行工具)总是最好直接使用来调用正确的API系统插件.

Using external tools is not always a good idea (Not every command line tool exists on the Home versions of windows ) It's always better to call the correct API directly with the system plug in.

!include LogicLib.nsh

StrCpy $0 "c:\"
System::Call 'Kernel32::GetVolumeInformation(t "$0",t,i ${NSIS_MAX_STRLEN},*i,*i,*i,t.r1,i ${NSIS_MAX_STRLEN})i.r0'
${If} $0 <> 0
    MessageBox mb_ok "fs=$1"
${EndIf}

但是在这种情况下,您不应检查文件系统类型,而应查找所需的实际功能(压缩,加密,连接,稀疏文件等)

But in this case, you should not be checking the file system type, but you should look for the actual feature you need (compression,encryption,junctions,sparse files etc)

!define FILE_SUPPORTS_ENCRYPTION 0x00020000
!define FILE_READ_ONLY_VOLUME 0x00080000
!define FILE_VOLUME_QUOTAS 0x00000020

!macro MakeBitFlagYesNo flags bit outvar
IntOp ${outvar} ${flags} & ${bit}
${IfThen} ${outvar} <> 0 ${|} StrCpy ${outvar} "Yes" ${|}
${IfThen} ${outvar} == 0 ${|} StrCpy ${outvar} "No" ${|}
!macroend

StrCpy $0 "c:\"
System::Call 'Kernel32::GetVolumeInformation(t "$0",t,i ${NSIS_MAX_STRLEN},*i,*i,*i.r1,t,i ${NSIS_MAX_STRLEN})i.r0'
${If} $0 <> 0
    !insertmacro MakeBitFlagYesNo $1 ${FILE_SUPPORTS_ENCRYPTION} $2
    !insertmacro MakeBitFlagYesNo $1 ${FILE_READ_ONLY_VOLUME} $3
    !insertmacro MakeBitFlagYesNo $1 ${FILE_VOLUME_QUOTAS} $4
    MessageBox mb_ok "flags=$1 $\nFILE_SUPPORTS_ENCRYPTION=$2$\nFILE_READ_ONLY_VOLUME=$3$\nFILE_VOLUME_QUOTAS=$4"
${EndIf}

这篇关于使用NSIS检测目标卷是否为NTFS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆