steventnorris
steventnorris

Reputation: 5896

Convert code to C# from VB script

I am attempting to transition from VB script to C# with some legacy code that a colleague has. I cannot seem to determine how to transfer this line over. Any assistance would be helpful.

Set objShell = CreateObject("wscript.shell")
objShell.Run """C:\Program Files\Ipswitch\WS_FTP Professional\ftpscrpt.com"" -f P:\share\getfiles.scp", 1, True
Set objShell = Nothing

Upvotes: 2

Views: 2405

Answers (3)

Jason
Jason

Reputation: 3960

This is from some old note I dug up, but should work:

Process proc = new Process();

proc.StartInfo.FileName = @"C:\Program Files\Ipswitch\WS_FTP Professional\ftpscrpt.com";
proc.StartInfo.Arguments = @"-f P:\share\getfiles.scp";
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.UseShellExecute = false;
// start the process
proc.Start();
// wait for it to finish
proc.WaitForExit(5000);     
// get results
string output = proc.StandardOutput.ReadToEnd();
string error = proc.StandardError.ReadToEnd();

Upvotes: 2

thmshd
thmshd

Reputation: 5847

See the example (Scroll down to examples) for information on executing the command. You can try to change the UseShellExecute option to get a close result.

Upvotes: 1

Douglas Barbin
Douglas Barbin

Reputation: 3615

I suppose the exact C# equivalent would be this:

var objShell = Microsoft.VisualBasic.Interaction.CreateObject("wscript.shell");
objShell.Run("\"C:\\Program Files\\Ipswitch\\WS_FTP Professional\\ftpscrpt.com\\" -f P:\share\getfiles.scp", 1, true);
objShell = null;

But really, you should just add a reference to the assembly in question and call its methods directly.

Upvotes: 1

Related Questions