We help IT Professionals succeed at work.

run script from vb.net

TREER
TREER asked
on
Medium Priority
409 Views
Last Modified: 2012-05-05
I Have a vb.net prog which contains a flie "vbscript1.vbs" simply i need to click a button and for the script to run
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2007

Commented:
Try:

System.Diagnostics.Process.Start ("c:\PathtoScript\vbscript1.vbs")
CERTIFIED EXPERT

Commented:
Dim obj as new Process
obj.start("\\server\share\folder\vbscript1.vbs")


You can use obj.WaitForExit() method to wait till the process has
termintated.

Author

Commented:
unfortunately, your ideas do not work although they nearly do
the following error occurs when i attempt your code

line
char 1
error Object expected
code 800A138F
Source Microsoft jscript runtime error

so i replaced my javascript code  with a simple
 alert("try")

but still the same error occurs

 i have increased the points to 500, many thanks for your time


CERTIFIED EXPERT
Top Expert 2007

Commented:
This indicates that it 'is' working - but reporting back an error in the called script..
Commented:
Here is an "in process" way to run a vbscript using a COM-based DLL

        ' Include a COM reference to "Microsoft Script Control" (MSScriptControl)
        Dim host As New MSScriptControl.ScriptControlClass

        host.Language = "VBScript"
        host.AddCode("Sub main" & vbCr & "Msgbox(""Hello"")" & vbCr & "End Sub")
        host.Run("main")

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
sirbounty ,

i can see your logic, and indeed that was my first thought, that is why i replaced my original script with just the one line


alert("try")

the result was the same error



graye, the script is javascript, will this be the same?
CERTIFIED EXPERT
Top Expert 2007

Commented:
I don't know much about javascript, but that's a vb script you're trying to run and alert("try") is not a valid command...
try

wscript.echo "Hello"

instead...

Commented:
You can run VB.Net Shell() function to execute the script as simple as possible:
http://www.dotnet247.com/247reference/msgs/57/289295.aspx
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.