tkaragiris posted on August 31, 2010 09:57

This function allows the execution of a DOS command like XCOPY from VB .net:
''' <summary>
''' Execute DOS Command
''' </summary>
''' <param name="strCommand">"xcopy c:\temp\*.* \\test\temp /y"</param>
''' <returns></returns>
''' <remarks></remarks>
Public Function ExecuteDOSCommand(ByVal strCommand As String) As String
Dim processXCopy As New System.Diagnostics.Process
processXCopy.StartInfo.FileName = "cmd"
processXCopy.StartInfo.Arguments = "/c " & strCommand
processXCopy.Start()
processXCopy.WaitForExit()
Dim strError As String = ""
Select Case processXCopy.ExitCode
Case 0
' No error
Case Else
strError = "An error occurred replicating files."
End Select
Return strError
End Function