Force a VBS to run using cscript instead of wscript

前端 未结 5 1558
予麋鹿
予麋鹿 2020-12-29 07:42

What is the stackoverflow approved (and hence correct) method to force a VBS to run using cscript instead of wscript - irrespective of what the user tries?

A quick G

5条回答
  •  悲&欢浪女
    2020-12-29 08:15

    Two small additions to forceCScriptExecution let me see its Window after termination and handle its return code.

    Sub forceCScriptExecution
        Dim Arg, Str
        If Not LCase( Right( WScript.FullName, 12 ) ) = "\cscript.exe" Then
            For Each Arg In WScript.Arguments
                If InStr( Arg, " " ) Then Arg = """" & Arg & """"
                Str = Str & " " & Arg
            Next
            **ret =** CreateObject( "WScript.Shell" ).Run **("cmd /k** cscript //nologo """ & WScript.ScriptFullName & """ " & Str**,1,true)**
            WScript.Quit **ret**
        End If
    End Sub
    

    Notes: "cmd /k" let the windows stay after execution. Parameter "1" activates the window. Parameter "true" waits for termination, so variable "ret" can return the error code.

提交回复
热议问题