VBScripts

  • Thread starter Thread starter Jim Rasmussen
  • Start date Start date
J

Jim Rasmussen

I am trying to run/execute a .vbs file from c# as a process. Is this
possible? If so, how.

TIA

Jim
 
Jim,

Yes, you can just use the Process class and pass the path to the script
and it should execute it.

You might want to consider translating the script into C#, as it might
make maintaining the code easier.
 
Nicholas,
Thanks for the quick reply. here is what I have....

ProcessStartInfo psi = new ProcessStartInfo(Server.MapPath("render.vbs"));
psi.UseShellExecute = false;
psi.Arguments = ExamID.ToString() + " compexam.xsl";
Process.Start(psi);

when stepping thru the previous code, an error is encountered that states
"The specified executable is not a valid Win32 application"

and when this code is executed, all that happens is a beep. The code in
render.vbs is ...
Option Explicit
MsgBox("hello world") //this is just to test the execution of the
vbs file
using (Process oProc = new Process())

{

oProc.StartInfo.FileName = Server.MapPath("render.vbs");

oProc.StartInfo.Arguments = ExamID.ToString() + " compexam.xsl";

oProc.Start();

oProc.WaitForExit(10000);

}



Thanks for you input,

Jim

Nicholas Paldino said:
Jim,

Yes, you can just use the Process class and pass the path to the script
and it should execute it.

You might want to consider translating the script into C#, as it might
make maintaining the code easier.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jim Rasmussen said:
I am trying to run/execute a .vbs file from c# as a process. Is this
possible? If so, how.

TIA

Jim
 
Well I changed
psi.UseShellExecute = false;
to
psi.UseShellExecute = true;

no error just the system beep.

Thanks
Jim

Jim Rasmussen said:
Nicholas,
Thanks for the quick reply. here is what I have....

ProcessStartInfo psi = new ProcessStartInfo(Server.MapPath("render.vbs"));
psi.UseShellExecute = false;
psi.Arguments = ExamID.ToString() + " compexam.xsl";
Process.Start(psi);

when stepping thru the previous code, an error is encountered that states
"The specified executable is not a valid Win32 application"

and when this code is executed, all that happens is a beep. The code in
render.vbs is ...
Option Explicit
MsgBox("hello world") //this is just to test the execution of the
vbs file
using (Process oProc = new Process())

{

oProc.StartInfo.FileName = Server.MapPath("render.vbs");

oProc.StartInfo.Arguments = ExamID.ToString() + " compexam.xsl";

oProc.Start();

oProc.WaitForExit(10000);

}



Thanks for you input,

Jim

Nicholas Paldino said:
Jim,

Yes, you can just use the Process class and pass the path to the
script and it should execute it.

You might want to consider translating the script into C#, as it might
make maintaining the code easier.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jim Rasmussen said:
I am trying to run/execute a .vbs file from c# as a process. Is this
possible? If so, how.

TIA

Jim
 
I am trying to run/execute a .vbs file from c# as a process. Is this
possible? If so, how.

TIA

Jim

First of all before you try anything be sure to check your anti-virus
software's functionality. Symantec for instance will silently kill any
attempts to run scripts in this way
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top