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?
Printable View
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?
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.
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
Thank you I have it working now.