Sunday, December 09, 2007

Running vbs from .net code

There are a few ways to run vbscript inside vb.net. If you just need the script to run, you can use the process object.


Dim oProcess as new Process
Try
oProcess.StartInfo.UseShellExecute = True
oProcess.StartInfo.FileName = "CScript c:\script.vbs //nologo"
oProcess.Start()
oProcess.WaitForExit()
Finally
oProcess.Dispose()
End Try

Process Class

If you have some VBScript that you want to intereact with variables or run on the fly. Microsoft has a ScriptControl that allows you to do just that. The script control has 3 options of running code.
  • Eval: Evaluates a text expression.
  • Run: Runs a named Sub or Function.
  • Execute: Executes a script statement.

You can find more information on the ScriptControl at Microsoft.
Q184740: How To Call Functions Using the Script Control
Q184739: INFO: Where to Obtain the Script Control


If you are looking to run vb.net code inside vbscript, see my other post:
Running VB.NET code in VBScript or other apps

No comments:

Post a Comment