我的vb.net应用程序存在这个问题,它使用CMD函数将文件复制到驱动器。
以下是代码:
Shell类:
Public Class Shell
Dim p As Process
Dim thread As System.Threading.Thread
Public Event TextToSend(ByVal sText As String)
Public Sub Start()
p = New Process
p.StartInfo.FileName = "cmd"
p.StartInfo.Arguments = Nothing
p.StartInfo.CreateNoWindow = True
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardError = True
p.StartInfo.RedirectStandardInput = True
p.StartInfo.RedirectStandardOutput = True
p.Start()
thread = New System.Threading.Thread(AddressOf ReciveOutput)
thread.IsBackground = True
thread.Start()
p.WaitForExit()
End Sub
Public Sub SendCMD(ByVal Command As String)
Try
p.StandardInput.WriteLine(Command)
p.StandardInput.Flush()
Catch ex As Exception
End Try
End Sub
Sub ReciveOutput()
While True
Try
Dim output As String = p.StandardOutput.ReadLine
If output <> Nothing Then
RaiseEvent TextToSend(output)
End If
Catch ex As Exception
End Try
End While
End Sub
Sub StopProcess()
Try
p.Kill()
thread.Abort()
Catch ex As Exception
End Try
End Sub
End Class
表格类:
For Each drive In drive_list
'Then loop
For Each lvi As ListViewItem In ListView2.Items
Shell.SendCMD("copy /z /y C:\Users\thomas1\Downloads\File.img E:\")
'Wait here until process has finished
Next
Next
我一直面对这个问题。我需要让它输出进度,例如。 &#34; 13%复制&#34;。