|
Public Const drv As String = "M:"
Public Const pth As String = "\\ファイルサーバーA\Shared"
Public Const usr As String = "UserA"
Public Const pwd As String = "12345"
Sub 接続()
Dim objNetwork As Object
Dim colDrives As Object
Dim i As Integer
Set objNetwork = CreateObject("WScript.Network")
Set colDrives = objNetwork.EnumNetworkDrives
For i = 0 To colDrives.Count - 1 Step 2
If colDrives.Item(i) = drv Then Exit Sub
Next
On Error GoTo er
objNetwork.MapNetworkDrive drv, pth, False, usr, pwd
Set objNetwork = Nothing
Set colDrives = Nothing
Exit Sub
er:
MsgBox "接続失敗"
End Sub
Sub 切断()
Dim objNetwork As Object
Dim colDrives As Object
Dim i As Integer
On Error GoTo er
Set objNetwork = CreateObject("WScript.Network")
Set colDrives = objNetwork.EnumNetworkDrives
For i = 0 To colDrives.Count - 1 Step 2
If colDrives.Item(i) = drv Then
objNetwork.RemoveNetworkDrive drv, True
End If
Next
Set objNetwork = Nothing
Set colDrives = Nothing
Exit Sub
er:
MsgBox "切断失敗"
End Sub
|
|