Results 1 to 4 of 4

Thread: [RESOLVED] How do I run a .vbs?

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2008
    Posts
    2

    Resolved [RESOLVED] How do I run a .vbs?

    I have a .vbs that I am trying to run. Right now the .vbs extension is associated with notepad on my computer, so if I double click it it just opens in notepad. How do I run the script?
    Last edited by Hack; May 31st, 2008 at 04:47 AM. Reason: Added RESOLVED to thread title and green resolved checkmark

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: How do I run a .vbs?

    A .vbs file can be one of two things: a "naked VBScript" WSH script or a VBScript include file for use in a .wsf, .htm, or .hta file. The default for a Shell open on a .vbs file is to open it in wscript.exe but this is often changed to cscript.exe on servers.

    It is possible for some security software suites or local security policies to disable or remove wscript or cscript.

    Assuming that is not the case you should be able to restore the Shell verb to its original state by right-clicking and selecting Open with... and choosing wscript.exe checking "always use the selected program..." Details vary by Windows OS.

    You can also simply type:
    wscript file.vbs
    ... from a command prompt.

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How do I run a .vbs?

    Welcome to the Forums

    ShellExecute the vbs file.


    Code:
    Option Explicit
    
    Private 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
    
    Private Const SW_HIDE As Long = 0
    Private Const SW_SHOWNORMAL As Long = 1
    Private Const SW_SHOWMAXIMIZED As Long = 3
    Private Const SW_SHOWMINIMIZED As Long = 2
    
    Private Sub Command1_Click()
        ShellExecute Me.hwnd, "open", "C:\Users\Public\myscript.vbs", vbNullString, "C:\", SW_SHOWNORMAL
    End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2008
    Posts
    2

    Re: How do I run a .vbs?

    Thank you I have it working now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width