Force a VBS to run using cscript instead of wscript

前端 未结 5 1559
予麋鹿
予麋鹿 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:05

    Here is my code snippet i use for some of my scripts. It handles Arguments as well. All you have to do is replace the {EnterWorC} with either a "w" or "c" WITH quotes

    Dim WorC, Command, Arguments, I
    
    WorC={EnterWOrC}  'Make sure you replace "{EnterWOrC}" with a "w" or a "c" and BE SURE TO PUT QUOTES AROUND THE LETTER.
    
    WorC=LCase (WorC)
    If lcase (WorC)="w" Or lcase (WorC)="c" Then
    
    If LCase (Right (WScript.FullName,11))<> WorC & "script.exe" Then
        command=WScript.ScriptFullName
        Arguments=""
        For I=0 To UBound (WScript.Arguments)
            Arguments=Arguments & Chr (34) & WScript.Arguments(I) & Chr (34) & Space (1)
        Next
        CreateObject("Wscript.Shell").Run WorC & "script.exe " & Chr (34) & command & Chr (34) & Space (1) & Arguments, 1
        WScript.Quit
    End If
        WorC=Empty
        Command=Empty
        I=Empty
        Arguments=Empty
    End If
    

    Here you will have to replace the 2nd line (2nd NON-blank line)

    WorC={EnterWOrC}  'Make sure you replace "{EnterWOrC}" with a "w" or a "c" and BE SURE TO PUT QUOTES AROUND THE LETTER.
    

    For Wscript: WorC="W"

    For CScript: WorC="C"

    It is NOT case Sensitive.

提交回复
热议问题