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
Using a site like StackOverflow as an example: I have a table of users,
Hi Stackoverflow i hope you are all well today, i seem to have run
The StackOverflow question using static keyword in objective-c when defining a cached variable references
i wanted to see if stackoverflow was using a seperate plugin to do those
I would like to use the search method of stackoverflow API to return the
Hi stackoverflow community, i'm using RKObjectManager to make iOS RESTful requests to map responses
Hi stackoverflow friends, I need to take a picture using camera and after takin
I have another StackOverflow question on how to install and run a custom checkstyle.

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.