2

私の VB6 プログラムは、ネットワーク共有上にあるデータに依存しています。ワイヤレス ネットワーク上の Win XP は、多くの場合、起動時にマップされたドライブを再接続できないため、ドライブは切断された状態になります。それらを再接続する唯一の方法は、エクスプローラーでそれらをダブルクリックすることです。

プログラムでこれを行うにはどうすればよいですか? それを行う API 呼び出しはありますか?

4

3 に答える 3

2

WNetAddConnection関数を使用できます

Private Sub cmdMapDrive_Click()
Dim drive_letter As String
Dim share_name As String
Dim password As String

    lblResult.Caption = "Working..."
    Screen.MousePointer = vbHourglass
    DoEvents

    drive_letter = txtDriveLetter.Text
    If InStr(drive_letter, ":") = 0 _
        Then drive_letter = drive_letter & ":"
    share_name = txtShareName.Text
    password = txtPassword.Text

    If WNetAddConnection(share_name, password, _
        drive_letter) > 0 _
    Then
        lblResult.Caption = "Error mapping drive"
    Else
        lblResult.Caption = "Drive mapped"
    End If

    Screen.MousePointer = vbDefault
End Sub

コードソース:VBヘルパー

于 2011-03-17T14:31:09.020 に答える
1

dosコマンド""を使用して、vbの-コマンドnet useで開始できます。shell

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/net_use.mspx?mfr=true

于 2011-03-17T14:05:48.923 に答える
0

私はこれを次のようにしましたScripting.FileSystemObject

Public Function MapDrive(ByVal Sharename As String, DriveToMap As String) As Boolean

    On Error GoTo Handler

    Dim fso As Scripting.FileSystemObject
    Dim ntwk As IWshRuntimeLibrary.IWshNetwork_Class

    ' Assume success; any failure will invoke the error handler & cause '
    ' the function to return false. '
    MapDrive = True

    Set fso = New Scripting.FileSystemObject
    Set ntwk = New IWshRuntimeLibrary.IWshNetwork_Class

    ' If the specified drive doesn't even exist, just map it '
    If Not fso.DriveExists(DriveToMap) Then
        ntwk.MapNetworkDrive DriveToMap, Sharename
        Exit Function
    End If

    ' The drive already exists; see if it's already be mapped correctly. '
    If UCase(fso.Drives(DriveToMap).ShareName) = UCase(Sharename) Then
        Exit Function
    End If

    ' The drive is mapped, but to the wrong place. Unmap, then map the drive. '
    ntwk.RemoveNetworkDrive DriveToMap
    ntwk.MapNetworkDrive DriveToMap, Sharename
    Exit Function

Handler:
    MapDrive = False
    Err.Clear

End Function
于 2011-03-17T17:39:04.623 に答える