[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to run a VBScript?

Posted on 2005-04-11
6
Medium Priority
?
216 Views
Last Modified: 2010-05-02
Hi,

I want to make a function RunScript as specified below:

Function RunScript(ByVal Path As String) As Boolean

 * loads the file specified in the path
 * runs the VBScript code in the file
 * returns True on success

I ve managed to make such a function using the following component:
Microsoft Script Control 1.0

Unfortunatly I can not use components because the RunScript function will be part of an ActiveX DLL.

My question: How do I make the RunScript function without using the Microsoft Script Control 1.0 component?
Perhaps there is a scripting library I am unaware of? If so, which one and can you give me some examples on how to use that scripting library?

Thanks!

Osmodean
0
Comment
Question by:osmodean
6 Comments
 
LVL 17

Accepted Solution

by:
Thibault St john Cholmondeley-ffeatherstonehaugh the 2nd earned 2000 total points
ID: 13754135
Can you not just add the scriptcontrol as a reference instead of as a component?

then:

Dim scr as new ScriptControl

scr.Language = "vbScript"
 
scr.Eval("...string...")
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 13754338
How about ShellExecute API:


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 Sub Command1_Click()
MsgBox RunScript("C:\Somefile.vbs")
End Sub


Function RunScript(ByVal Path As String) As Boolean
Dim x As Long
x = ShellExecute(0, "Open", ("C:\Somefile.vbs"), "", "", 1)
If x = 0 Then
    RunScript = False
Else
    RunScript = True
End If
End Function
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 13754345
I meant:

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 Sub Command1_Click()
MsgBox RunScript("C:\Somefile.vbs")
End Sub


Function RunScript(ByVal Path As String) As Boolean
Dim x As Long
x = ShellExecute(0, "Open", (Path), "", "", 1)
If x = 0 Then
    RunScript = False
Else
    RunScript = True
End If
End Function
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 26

Expert Comment

by:EDDYKT
ID: 13755232
Try this

vbs

Dim varRetVal

'how to i read parameters and send to sub below"
Call testing(wscript.arguments(0),wscript.arguments(1),varRetVal)
MsgBox varRetVal

'want to return the value of valRetVal?
WScript.Quit 6

Public Sub testing(number1, number2,varRetVal)
   varRetVal = number1 + number2     '
End Sub



VB

Private Sub Command1_Click()
   Set wshell = CreateObject("WScript.Shell")
   str_Command = "C:\temp\Add.vbs 1 2"
    myvalue = wshell.Run(str_Command, 1, True)
    MsgBox myvalue
End Sub
0
 
LVL 6

Author Comment

by:osmodean
ID: 13774360
Thanks for all your answers, but RobinD gave me the answer I needed.
0
 
LVL 17
ID: 13774384
Thanks osmodean. Glad to help.
 
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

830 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