Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4022774
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:31:03+00:00 2026-05-20T10:31:03+00:00

What is the stackoverflow approved (and hence correct) method to force a VBS to

  • 0

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 Google search shows plenty of examples, but some of them simply don’t work and those which do often don’t handle the fact that it may have been run with arguments so I’m keen to know what the best way is.

Here is one example which doesn’t handle arguments:

sExecutable = LCase(Mid(Wscript.FullName, InstrRev(Wscript.FullName,"\")+1))
If sExecutable <> "cscript.exe" Then
  Set oShell = CreateObject("wscript.shell")
  oShell.Run "cscript.exe """ & Wscript.ScriptFullName & """"
  Wscript.Quit
End If

I appreciate that this could probably be easily modified to handle arguments, but realise that this may not be the best way to approach the problem.

Background: I’m writing a script which can run by double clicking or (most likely) from either a DOS batch file or as a scheduled task. It can contain one or more optional command line arguments.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:31:03+00:00Added an answer on May 20, 2026 at 10:31 am

    My Lord, what unadulterated rubbish. It makes me cry to see such cruddy coding (no offense to anybody, lol). Seriously, though, here’s my 2 pence:

    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
            CreateObject( "WScript.Shell" ).Run _
                "cscript //nologo """ & _
                WScript.ScriptFullName & _
                """ " & Str
            WScript.Quit
        End If
    End Sub
    forceCScriptExecution
    

    It handles arguments, AND checks for spaces in said arguments — so that in the case of a filename passed to the original script instance that contained spaces, it wouldn’t get “tokenized” when passed to cscript.exe.

    Only thing it doesn’t do is test for StdIn (e.g., in the case where someone piped something to the script via the command line, but forgot to use “cscript script.vbs”) — but if it was executed by WScript.exe, WScript.StdIn’s methods all return Invalid Handle errors, so there’s no way to test that anyway.

    Feel free to let me know if there’s a way to “break” this; I’m willing to improve it if necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

StackOverflow user jolson had a very nice piece of code that exemplifies how one
Stackoverflow User Luke wrote in this answer : The boundaries between desktop and web
Stackoverflow is built on MVC and does a bunch of simple but nice things
StackOverflow, you're my only hope! I am unfortunate enough to have inherited an ASP.NET
In StackOverflow podcast no. 19 , Joe describe Fogcreek's decision to have one database
Hey stackoverflow community! I'm having an issue where a highly involved algorithmic program is
I notice that StackOverflow has a views count for each question and that these
What do wikis/stackoverflow/etc. do when it comes to storing text? Is the text broken
How does Stackoverflow implement the resizable textarea? Is that something they rolled themselves or
I'm pretty sure stackoverflow.com is created with ASP.NET, but no matter where I click

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.