所以就隨手寫一下 ^^
------------------------------------------
Private Sub NetHD(ByVal Drives() As String, ByVal CurrentDrives As String, ByVal CurrentPath As String)
'查詢要使用連線的名稱是否存在
Dim ExistFlag As Boolean = False
For Each Drive As String In Drives
If Drive = CurrentDrives Then ExistFlag = True
Next
'網路磁碟機存在的處理
If ExistFlag = True Then
If MessageBox.Show("網路磁碟機已存在,請按YES中斷磁碟機" & vbNewLine & "或按NO離開連線磁碟機!") = Windows.Forms.DialogResult.Yes Then
Shell("NET USE " & Mid(CurrentDrives, 1, 2) & " /DELETE /YES")
Else
Exit Sub
End If
Else
Shell("NET USE " & Mid(CurrentDrives, 1, 2) & " " & CurrentPath & " /PERSISTENT:NO")
'測試是否已連線
Do Until IO.Directory.Exists(CurrentDrives) = False : Application.DoEvents() : Loop
MsgBox("網路磁碟機已連線!!")
End If
End Sub
Private Sub btnConnHD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnHD.Click
NetHD(IO.Directory.GetLogicalDrives, "Z:\", "\\Pub\Tools")
End Sub
------------------------------------
如果是想複製檔案的話可以加上
Dim fso As Object = CreateObject("Scripting.FileSystemObject")
fso.CopyFile(sPath, dpath, True)
Do Until fso.FileExists(dpath) = True : Application.DoEvents() : Loop
fso = Nothing
或下面的部份
File.Copy(sPath, dpath, True)
Do Until File.Exists(dpath) = True : Application.DoEvents() : Loop
------------------------------------
如果是想複製檔案的話可以加上
Dim fso As Object = CreateObject("Scripting.FileSystemObject")
fso.CopyFile(sPath, dpath, True)
Do Until fso.FileExists(dpath) = True : Application.DoEvents() : Loop
fso = Nothing
或下面的部份
File.Copy(sPath, dpath, True)
Do Until File.Exists(dpath) = True : Application.DoEvents() : Loop
沒有留言:
張貼留言