vb script

Posted on 2005-05-11
Last Modified: 2011-09-20
i write a vb script program and i named that file as "test.vbs".then how can i run that test.vbs file.
Question by:beeravally
    LVL 15

    Accepted Solution


    there are two straight forward ways

    1. Just double click the file to run it
    2. Open a command prompt and enter the file path and name to run it
      For example if the file is in the temp folder of the c drive use

    c:\temp\test.vbs at the command prompt


    LVL 8

    Assisted Solution


    wscript c:\test.vbs
    LVL 48

    Assisted Solution

    by:Ryan Chong
    or using shellexecute api, like:

    Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

    Public Function StartDoc(ByVal FileName As String, Optional CommandLine As String = "") As Long
        StartDoc = ShellExecute(0&, "Open", FileName, CommandLine, vbNullString, 1)
    End Function


    StartDoc "c:\test.vbs"
    LVL 26

    Assisted Solution

    Or from code

    Dim wshShell
    Set wshShell = CreateObject("WScript.Shell")
    wshShell.Run "c:\yourvbs.vbs", , True
    Set wshShell = Nothing
    LVL 48

    Expert Comment

    by:Ryan Chong
    I think mine only works inside Visual Basic, but not for pure .vbs file, so my suggestion:

    Accept EDDYKT's comment as the answer

    LVL 48

    Expert Comment

    by:Ryan Chong
    After re-read the question:
    >>i write a vb script program and i named that file as "test.vbs".then how can i run that test.vbs file.
    hmm..  am i contribute some here?? Will it fair that split among 3 of us, anyway, i will be happy with the final decision, cheers 8-)
    LVL 6

    Expert Comment

    question was how to run .vbs file, not how to run .vbs file inside .vbs file.
    Split between first two major concepts: 1) command line interactively  2) shell calls programmatically.

    LVL 48

    Expert Comment

    by:Ryan Chong
    Hi GPrentice00,

    EDDYKT's solution works in both .vbs and inside Visual Basic, so it's fair enough to give some points for EDDYKT for his contribution here.


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now