vbs脚本实现打开d盘pdf文件
答案:1 悬赏:40 手机版
解决时间 2021-02-05 16:36
- 提问者网友:雪舞兮
- 2021-02-04 16:17
vbs脚本实现打开d盘pdf文件
最佳答案
- 五星知识达人网友:夜余生
- 2021-02-04 17:06
下面的VBS脚本可以做到,测试通过。
Function X86orX64()
'用WMI方法判断操作系统是32位还是64位
On Error Resume Next
strComputer = "." 'localhost
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objItem in colItems
If InStr(objItem.SystemType, "86") <> 0 Then
X86orX64 = "x86"
ElseIf InStr(objItem.SystemType, "64") <> 0 Then
X86orX64 = "x64"
Else
X86orX64 = objItem.SystemType
End If
Next
End Function
'WScript.Echo X86orX64()
sysType = X86orX64()
If sysType = "x86" Then
progPath = "%ProgramFiles%" 'DOS窗口中用set命令查看环境变量
ElseIf sysType = "x64" Then
progPath = "%ProgramFiles(x86)%" 'DOS窗口中用set命令查看环境变量
Else
MsgBox sysType, vbExclamation, "Unexpected System Type"
WScript.Quit
End If
adobePath = progPath & "\Adobe\Reader 10.0\Reader\AcroRd32.exe"
'确定Adobe PDF Reader安装路径
pdfPath = "D:\Test.pdf" '要打开的PDF文件路径
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run Chr(34) & adobePath & Chr(34) & _
" " & Chr(34) & pdfPath & Chr(34)
'Chr(34)表示双引号,通常将路径放在双引号中以避免路径中空格带来的问题
Set WshShell = Nothing
Function X86orX64()
'用WMI方法判断操作系统是32位还是64位
On Error Resume Next
strComputer = "." 'localhost
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objItem in colItems
If InStr(objItem.SystemType, "86") <> 0 Then
X86orX64 = "x86"
ElseIf InStr(objItem.SystemType, "64") <> 0 Then
X86orX64 = "x64"
Else
X86orX64 = objItem.SystemType
End If
Next
End Function
'WScript.Echo X86orX64()
sysType = X86orX64()
If sysType = "x86" Then
progPath = "%ProgramFiles%" 'DOS窗口中用set命令查看环境变量
ElseIf sysType = "x64" Then
progPath = "%ProgramFiles(x86)%" 'DOS窗口中用set命令查看环境变量
Else
MsgBox sysType, vbExclamation, "Unexpected System Type"
WScript.Quit
End If
adobePath = progPath & "\Adobe\Reader 10.0\Reader\AcroRd32.exe"
'确定Adobe PDF Reader安装路径
pdfPath = "D:\Test.pdf" '要打开的PDF文件路径
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run Chr(34) & adobePath & Chr(34) & _
" " & Chr(34) & pdfPath & Chr(34)
'Chr(34)表示双引号,通常将路径放在双引号中以避免路径中空格带来的问题
Set WshShell = Nothing
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯