使用 VBS 确定程序文件的位置
使用 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
What would a safe way of extracting the 'Program Files' directory location using VBS?. I would like to get the directory location from the environment as it will avoid localization issues as well as problems between different OS architectures (32/64 bit) and drive (C:\, D:\, etc:).
So far I came across an example given on MSDN yet I can get the script to work in VBS, every run just complains about different errors. Here is what they've got on an example script for .net to get the Sys32 folder.
' 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
'
As Helen mentioned, this is my script to determine the OS Architecture and depending on the outcome I wish to retrieve the respective 'Program Files' path
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如何从 VBScript 获取程序文件环境设置
对于 vbs,来自 如果您使用的是 vba,
for vbs from How to get program files environment setting from VBScript
if you are in vba