Skip to content

Josh's IT-Blog

Information Technology, and other interesting things …

  • Home
  • About
  • Contact
  • Links
  • Home
  • About
  • Contact
  • Links

force a vbscript to run in CSCRIPT

  1. Home   »  
  2. force a vbscript to run in CSCRIPT

force a vbscript to run in CSCRIPT

28. September 201228. September 2012 Burkard JoshWindows 7Tagged VBScript

There are several valid reasons to demand that a vbscript runs in CSCRIPT instead of WSCRIPT, like for example to allow the use of Standard Input or to prevent a separate popup for each Wscript.Echo line.

The following code can be copied and pasted at the top of your own scripts to force them to run in CSCRIPT:

If (right(Ucase(WScript.FullName),11)="WSCRIPT.EXE") Then
    Dim WshShell,args,objArgs,I
    Set WshShell = CreateObject("WScript.Shell")
    args=""
    If Wscript.Arguments.Count > 0 Then
        Set objArgs = WScript.Arguments
        For I = 0 to objArgs.Count - 1
            args = args & " " & objArgs(I)
        Next
    End If
    Set objDebug = WshShell.Exec ( "cscript.exe /NoLogo """ & Wscript.ScriptFullName & """" & args )

    ' Wait until the script exits
    Do While objDebug.Status = 0
        WScript.Sleep 100
    Loop

    ' Exit with CSCRIPT's return code
    WScript.Quit objDebug.ExitCode
End If

The code may look more complicated than necessary, that’s because it returns CSCRIPT‘s return code to the WSCRIPT engine, just in case this return code is monitored by the program that started the script in WSCRIPT.

In case you want to force a script to run in WSCRIPT instead, just substitute WSCRIPT.EXE for CSCRIPT.EXE.

Post navigation

Previous: backup Cisco configurations
Next: add second default route to Synology NAS

About

Author Image
My name is Josh Burkard.
I'm a DevOps Engineer working with one of Europees largest payroll provider. in my work I have a lot to do with Microsoft server operating systems, System Center, VMware, Microsoft Azure Cloud and other software.
On this site I will write some posts about different technology problems and their solutions.
please note also my tweets and retweets from this area.

Categories

  • General (13)
  • Hardware (9)
    • Network (8)
      • Cisco (2)
    • Storage (2)
  • Hiking (1)
  • Home Assistant (5)
  • Microsoft Azure (1)
    • Automation (1)
  • PowerShell (3)
  • Software (1)
    • Excel (1)
  • System Center (18)
    • SCCM (3)
    • SCDPM (1)
    • SCOM (12)
    • SCSM (1)
    • SMA (1)
  • VMware (8)
  • Windows 2008 R2 (10)
    • Active Directory (7)
  • Windows 2012 R2 (1)
  • Windows 2016 (1)
  • Windows 7 (4)
    • BitLocker (1)
  • WordPress (1)
Proudly powered by WordPress | Theme: goldy-mex by inverstheme.