Vb6 WScript.Shell错误“;方法'~';对象的'~';“失败”;
它应该运行schedule.exe隐藏…但程序崩溃与Vb6 WScript.Shell错误“;方法'~';对象的'~';“失败”;,vb6,wsh,Vb6,Wsh,它应该运行schedule.exe隐藏…但程序崩溃与 public sub Main() Set objShell = CreateObject("WScript.Shell") strCommand = "C:/Program Files/s/schedule.exe" objShell.Run strCommand, vbHide, True Unload Me end sub 基本上,我需要schedule.exe在不中断用户的情况下以静默方式运行。如果您参考了Windows脚本主机
public sub Main()
Set objShell = CreateObject("WScript.Shell")
strCommand = "C:/Program Files/s/schedule.exe"
objShell.Run strCommand, vbHide, True
Unload Me
end sub
基本上,我需要schedule.exe在不中断用户的情况下以静默方式运行。如果您参考了
Windows脚本主机对象模型
,您将收到以下更具描述性的错误消息:
Runtime error '-2147024894 (80070002)' :
method '~' of object '~' failed
这可能提示您,如果可执行文件包含以下空格,则必须引用该文件名:
Automation error
The system cannot find the file specified.
您不需要使用WScript:只需使用带有vbHide参数的函数即可
Public Sub Main()
Dim objShell As Object ' WshShell
Dim strCommand As String
Set objShell = CreateObject("WScript.Shell")
strCommand = "C:/Program Files/7-zip/7z.exe"
objShell.Run """" & strCommand & """", vbHide, True ' WshHide
End Sub
我编译了这个,基本上,它没有隐藏7z.exe将它放在
Form1
中的一个单独的项目中,并从Form\u Load
事件调用它。刚刚测试了它,它确实产生了7-zip,并且隐藏了控制台。为什么不只是这样呢<代码>Shell“C:\Program Files\s\schedule.exe”,vbHide我认为OP希望等待Shell进程完成。
Shell "C:\Program Files\s\schedule.exe", vbHide