Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27159

file copy from network share to remote pc

$
0
0
Task : to copy file from network share to remote computer

I did wrote a code to copy using file.copy or async method, but as i am running it from my pc , it eats up my pc speed so
thought using psexec and below is working code , but i need an input from you guys if anyone can give better idea

i have placed progress bar so that, it can tell me if copy is still in process

The server needs diff. credentials and that's the reason i am using psexec here, i am thinking of using wmi (but some pc might behind the firewall)

i guess i don't need the batch file, but still creating batch as the long path might create some issues

any better solution , please suggest



Imports System.Diagnostics
Imports System.Threading

Public Class Form1

Private trd As Thread
Dim runningThreads As Integer = 0
Dim waitHandle As AutoResetEvent = New AutoResetEvent(False)


Private Sub CmdBatch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdBatch.Click

'Creating Batch file

Dim strData1 As String = "c:\pstools\psexec \\sppc cmd /c copy "
strData1 = strData1 & Space(1) & Chr(34) & txtSrcPath.Text & Chr(34)
strData1 = strData1 & Space(1) & Chr(34) & TxtTargetPath.Text & "" & Chr(34)

' \\server\folder\filename.zip \\computer\c$\temp"

CmdBatch.Text = "Make Batch"
MakeBAT(strData1, txtBatchFile.Text, )
CmdBatch.Text = "Batch Done"

End Sub

Public Function MakeBAT(ByVal strData As String, ByVal FullPath As String, Optional ByVal ErrInfo As String = "") As Boolean
Dim Contents As String = ""
Dim bAns As Boolean = False
Dim objReader As IO.StreamWriter
Try
objReader = New IO.StreamWriter(FullPath)
objReader.Write(strData)
objReader.Close()
bAns = True
Catch Ex As Exception
'ErrInfo = Ex.Message
End Try
Return bAns



End Function


Private Sub btnRunBatch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRunBatch.Click
'ShellSync(txtBatchFile.Text, AppWinStyle.NormalFocus)
pBar.Style = ProgressBarStyle.Marquee
pBar.MarqueeAnimationSpeed = 100
trd = New Thread(AddressOf ThreadTask)
trd.IsBackground = True
trd.Start()
waitHandle.WaitOne()
pBar.MarqueeAnimationSpeed = 0
MsgBox("Over")

End Sub

Private Sub ThreadTask()
Dim psi As New ProcessStartInfo(txtBatchFile.Text)
psi.RedirectStandardError = True
psi.RedirectStandardOutput = True
psi.CreateNoWindow = True
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.UseShellExecute = False
Dim process As Process = process.Start(psi)
process.WaitForExit()
waitHandle.Set()

End Sub



End Class

Viewing all articles
Browse latest Browse all 27159

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>