-2

i am trying to run a .vbs script that is not in the same directory as the program is in

Dim CustomInstalaionPath As String = "C:\Users\user\Desktop\Test"
Process.Start(CustomInstalationPath + "/run.vbs")

the program is running in the normal directory for de-bugging

C:\Users\user\Documents\Visual Studio 2010\Projects...

i have tried loads of ways but nothing is successfully running it

any help would be awesome thanks

Jason Down
  • 21,731
  • 12
  • 83
  • 117
reblerebel
  • 43
  • 2
  • 8

1 Answers1

2

You need to use the version of Process.Start that takes a ProcessStartInfo structure.

This will allow you to set the WorkingDirectory property, which is what you're looking for.

Something like:

Dim p As New System.Diagnostics.Process 

p.StartInfo.FileName = "cscript"
p.StartInfo.Arguments = "//B //Nologo C:\Users\user\Desktop\Test\myfile.vbs"
p.StartInfo.WorkingDirectory = "C:\Users\user\Desktop\Test"

p.Start(p.StartInfo) 

Also see this question (for C# that uses the same class). If you check it out, make sure to add the WorkingDirectory property:

Community
  • 1
  • 1
Merlyn Morgan-Graham
  • 58,163
  • 16
  • 128
  • 183