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

VBA调用oShell.Exec时偶发80070005(拒绝访问)错误求助

VBA调用oShell.Exec时偶发80070005(拒绝访问)错误求助

大家好,我遇到一个特别棘手的偶发问题,想请各位帮忙分析下!

我碰到的完整错误提示是:
Run-time error -2147024891 (80070005):

最奇怪的是这个错误不是每次都会出现——有时候程序运行完全正常,有时候就突然弹出这个「拒绝访问」的错误。我特意试过不使用管理员权限,手动在命令提示符里执行对应的命令,是可以正常运行的,没有任何权限问题。

通过调试我定位到,代码会卡在这一行:
Set oExec = oShell.Exec(sCmd)

这里的sCmd具体内容是:
C:\Program Files\ANSYS Inc\Shared Files\Licensing\winx64\lmutil lmstat -c 1055@ansyslmserver -f

下面是我用到的完整函数代码:

Public Function ShellRun(sCmd As String) As String

'Run a shell command, returning the output as a string

Dim oShell As Object
Set oShell = CreateObject("WScript.Shell")

'run command
Dim oExec As Object
Dim oOutput As Object
Set oExec = oShell.Exec(sCmd)
Set oOutput = oExec.StdOut

'handle the results as they are written to and read from the StdOut object
Dim s As String
Dim sLine As String
While Not oOutput.AtEndOfStream
    sLine = oOutput.ReadLine
    If sLine <> "" Then s = s & sLine & vbCrLf
Wend

ShellRun = s

End Function

非常感谢各位能提供一些排查方向或者解决办法!

备注:内容来源于stack exchange,提问作者Orbit

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.21 07:12:57