You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

32位模式下Inno Setup如何检测System32\Drivers中的gpiotom.sys文件

32位程序检测64位System32目录下sys文件的解决方案

这是典型的Windows文件系统重定向导致的问题——当32位程序在64位Windows上运行时,系统会自动把对C:\Windows\System32的访问重定向到C:\Windows\SysWOW64(32位系统文件目录),所以你的FileExists函数其实是在找SysWOW64里的文件,而非真正的System32\Drivers目录。

下面给你几种可靠的解决方法,适用于不同的脚本环境:

方法1:使用Sysnative特殊目录别名

64位Windows给32位程序提供了一个特殊的虚拟目录Sysnative,直接指向真正的System32目录。你可以用它来构造正确的文件路径,无需修改系统重定向设置。

PowerShell示例(32位模式)

# 判断当前系统是否为64位
$is64BitOS = [Environment]::Is64BitOperatingSystem
$windowsDir = [Environment]::GetEnvironmentVariable('windir', 'Machine')

# 根据系统位数构造路径
if ($is64BitOS) {
    $targetPath = Join-Path -Path $windowsDir -ChildPath 'Sysnative\Drivers\gpiotom.sys'
} else {
    $targetPath = Join-Path -Path $windowsDir -ChildPath 'System32\Drivers\gpiotom.sys'
}

# 检测文件是否存在
if (Test-Path -Path $targetPath -PathType Leaf) {
    Write-Host "✅ gpiotom.sys 存在于 System32\Drivers 目录"
} else {
    Write-Host "❌ 未找到 gpiotom.sys"
}

VBScript示例

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

windir = objShell.ExpandEnvironmentStrings("%WINDIR%")
' 检测系统是否为64位(通过判断Sysnative目录是否存在)
is64BitOS = objFSO.FolderExists(windir & "\Sysnative")

If is64BitOS Then
    targetPath = windir & "\Sysnative\Drivers\gpiotom.sys"
Else
    targetPath = windir & "\System32\Drivers\gpiotom.sys"
End If

If objFSO.FileExists(targetPath) Then
    WScript.Echo "gpiotom.sys 存在"
Else
    WScript.Echo "未找到 gpiotom.sys"
End If

方法2:临时关闭文件系统重定向(API方式)

如果你的脚本环境支持调用Windows API,可以临时关闭重定向,完成检测后再恢复。这种方法更底层,适合需要直接操作System32目录的场景。

比如在C++或者支持API调用的脚本中,使用Wow64DisableWow64FsRedirection和Wow64RevertWow64FsRedirection函数:

#include <windows.h>
#include <shlwapi.h>

BOOL IsGpiotomSysExists() {
    BOOL exists = FALSE;
    PVOID oldValue = NULL;

    // 关闭64位文件系统重定向
    if (Wow64DisableWow64FsRedirection(&oldValue)) {
        exists = PathFileExists(L"C:\\Windows\\System32\\Drivers\\gpiotom.sys");
        // 恢复重定向
        Wow64RevertWow64FsRedirection(oldValue);
    } else {
        // 如果关闭失败(比如在32位系统上),直接检测原路径
        exists = PathFileExists(L"C:\\Windows\\System32\\Drivers\\gpiotom.sys");
    }

    return exists;
}

方法3:安装程序脚本(如Inno Setup)

如果你用的是Inno Setup这类安装脚本工具,直接使用内置的{sysnative}常量即可访问真正的System32目录:

if FileExists(ExpandConstant('{sysnative}\Drivers\gpiotom.sys')) then
begin
    MsgBox('gpiotom.sys 已找到!', mbInformation, MB_OK);
end
else
begin
    MsgBox('未找到 gpiotom.sys', mbError, MB_OK);
end;

注意事项

  • Sysnative别名仅在32位程序运行于64位Windows时有效,32位系统上不存在这个目录,所以一定要先判断系统位数。
  • 临时关闭重定向后务必恢复,否则可能导致后续的文件操作出现异常。

内容的提问来源于stack exchange,提问作者harish sai

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:55:54