使用 VBS 提取“程序文件”目录位置的安全方法是什么?我想从环境中获取目录位置,因为它将避免本地化问题以及不同操作系统架构(32/64 位)和驱动器(C:\、D:\ 等:)之间的问题。
到目前为止,我遇到了MSDN上给出的示例,但我可以让脚本在 VBS 中工作,每次运行都会抱怨不同的错误。这是他们在 .net 示例脚本中获取Sys32文件夹的内容。
' Sample for the Environment.GetFolderPath method
Imports System
Class Sample
Public Shared Sub Main()
Console.WriteLine()
Console.WriteLine("GetFolderPath: {0}", Environment.GetFolderPath(Environment.SpecialFolder.System))
End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
'GetFolderPath: C:\WINNT\System32
'
正如海伦所提到的,这是我确定操作系统架构的脚本,根据结果我希望检索相应的“程序文件”路径
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & sPC & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
sSystemArchitecture = objOperatingSystem.OSArchitecture
Next