Search code examples
c#vbscriptcode-conversion

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

Solution

  • 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();