我如何从.vbs文件中打开另一个文件?

时间:2014-08-05 00:42:38

标签: batch-file vbscript

我如何从.vbs文件中打开另一个文件?

我想从vbscript文件运行file.bat,这两个文件位于以下文件夹中:http://i.imgur.com/9Gmuljz.png

3 个答案:

答案 0 :(得分:1)

执行批处理的另一种方法:

Option Explicit
Dim PathBatch,MyCommand
PathBatch = "%UserProfile%\Desktop\Folder1\Folder2\"
MyCommand = "CD /D " & DblQuote(PathBatch) & " & Start file.bat"
Call Run(MyCommand,1,False) 'Showing the console
'*********************************************************************************
Function Run(StrCmd,Console,bWaitOnReturn)
    Dim ws,MyCmd,Result
    Set ws = CreateObject("wscript.Shell")
'A value of 0 to hide the MS-DOS console
    If Console = 0 Then
        MyCmd = "CMD /C " & StrCmd & ""
        Result = ws.run(MyCmd,Console,bWaitOnReturn)
        If Result = 0 Then
            'MsgBox "Success"
        Else
            MsgBox "An unknown error has occurred!",16,"An unknown error has occurred!"
        End If
    End If
'A value of 1 to show the MS-DOS console
    If Console = 1 Then
        MyCmd = "CMD /K " & StrCmd & ""
        Result = ws.run(MyCmd,Console,bWaitOnReturn)
        If Result = 0 Then
            'MsgBox "Success"
        Else
            MsgBox "An unknown error has occurred!",16,"An unknown error has occurred!"
        End If
    End If
    Run = Result
End Function
'*********************************************************************************
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'*********************************************************************************

答案 1 :(得分:0)

也许喜欢

set kdshell = createobject("WScript.Shell")
kdshell.Run "./folder2/file.bat",0,false

答案 2 :(得分:0)

如果批处理文件位于当前目录中,您可以通过VB脚本调用批处理文件

      strcmd = "your_file.bat" + " " + "Arguments"

      wshshell.Run strcmd
相关问题