在Windows RT上的VBScript中,正在运行的脚本只能访问三个COM对象,其中一个是Scripting.FileSystemObject
。
如何仅使用FileSystemObject确定操作系统的处理器体系结构(在本例中为ARM
)?
通常我会查询HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
-> PROCESSOR_ARCHITECTURE
,或者我会WScript.Shell
用来获取系统级环境变量PROCESSOR_ARCHITECTURE
。但是,在这种情况下,我无法使用常规技术。
注意:我曾考虑过使用Scripting.FileSystemObject
来获取的文件版本ntoskrnl.exe
,这会告诉我我使用的是Windows版本6.3。然后在尝试创建WScript.Shell
对象并失败后,假设我必须在ARM Windows RT设备上。但是,这感觉很草率。已经有一段时间了,但是我已经看到了防病毒干扰了实例化VBScript中对象的能力的情况,我希望这段代码是准确/可靠的。
基于此答案,我能够构建一个健壮的VBScript函数,该函数从可执行文件的PE标头读取“计算机类型”。
功能和它的先决条件是太长,张贴在这里,但我已经在一个名为增加他们GetExecutableProcessorArchitectureFromFile.vbs
对我的GitHub仓库。
使用该函数GetExecutableProcessorArchitectureFromFile()
,我们可以使用以下代码获取Windows RT(或其他任何Windows操作系统)上的操作系统处理器体系结构:
' Note: it's best to get the Windows path programmatically; however, the scope of doing so is outside the scope of this question
strWindowsPath = "C:\Windows"
intReturnCode = GetExecutableProcessorArchitectureFromFile(strOSProcessorArchitecture, strWindowsPath & "\explorer.exe")
If intReturnCode >= 0 Then
WScript.Echo("OS Processor Architecture=" & strOSProcessorArchitecture)
End If
我已经在Intel IA-32(32位x86),AMD64 / Intel x86-x84(x64),ARM(32位),ARM64,Alpha,PowerPC和MIPS可执行文件上测试了此技术。
注意:我最终使用%WINDIR%\explorer.exe
了Windows XP,因为在所有支持VBScript的Windows版本中都存在explorer.exe,一直到运行VBScript 5.1的Windows 95为止。我比检查更好,C:\Windows\System32\ntoskrnl.exe
因为如果VBScript的进程恰好以Windows-on-Windows(WOW)进程的形式运行,例如在64位上的32位cscript.exe,则在此系统目录下将无法访问ntoskrnl.exe。视窗。这是因为Windows在这种情况下会将32位VBScript进程重定向到C:\ Windows \ SYSWOW64 \ ntoskrnl.exe,该文件不存在。SYSWOW64文件夹是64位Windows上32位进程的WOW64重定向路径。
注2:如果有人需要为如何以编程方式获得Windows路径的指针,看GetWindowsPath.vbs
在我的GitHub仓库。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句