vb6:objShell错误

时间:2010-02-14 07:34:25

标签: vb6

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隐藏....但程序崩溃

Runtime error '-2147024894 (80070002)' :
method '~' of object '~' failed

基本上我需要schedule.exe以静默方式运行而不会中断用户。

2 个答案:

答案 0 :(得分:0)

如果您引用Windows Script Host Object Model,则会收到更具描述性的错误消息:

Automation error
The system cannot find the file specified. 

如果它包含这样的空格,那么你可能会引用可执行文件名:

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

答案 1 :(得分:0)

您不需要使用WScript:只需将Shell函数与vbHide参数一起使用即可。

Shell "C:\Program Files\s\schedule.exe", vbHide