您的位置:首页 > 编程语言 > VB

vb 磁盘映射

2008-12-01 11:02 190 查看
VERSION 5.00

Begin VB.Form Form1

Caption = "Form1"

ClientHeight = 3195

ClientLeft = 60

ClientTop = 345

ClientWidth = 4680

LinkTopic = "Form1"

ScaleHeight = 3195

ScaleWidth = 4680

StartUpPosition = 3 '窗口缺省

Begin VB.TextBox Text1

Height = 360

Left = 1260

TabIndex = 1

Top = 1110

Width = 2475

End

Begin VB.CommandButton Command1

Caption = "Command1"

Height = 390

Left = 1515

TabIndex = 0

Top = 2220

Width = 1620

End

Begin VB.Label Label1

AutoSize = -1 'True

BackStyle = 0 'Transparent

Caption = "路径:"

Height = 180

Left = 525

TabIndex = 2

Top = 1125

Width = 540

End

End

Attribute VB_Name = "Form1"

Attribute VB_GlobalNameSpace = False

Attribute VB_Creatable = False

Attribute VB_PredeclaredId = True

Attribute VB_Exposed = False

Option Explicit

Private Const CONNECT_UPDATE_PROFILE =

Private Const RESOURCE_CONNECTED As Long = &H1

Private Const RESOURCE_GLOBALNET As Long = &H2

Private Const RESOURCETYPE_DISK As Long = &H1

Private Const RESOURCEDISPLAYTYPE_SHARE& =

Private Const RESOURCEUSAGE_CONNECTABLE As Long = &H1

Private Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETCONNECT, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long

Private Type NETCONNECT

dwScope As Long

dwType As Long

dwDisplayType As Long

dwUsage As Long

lpLocalName As String

lpRemoteName As String

lpComment As String

lpProvider As String

End Type

Public Function MapDrive(LocalDrive As String, RemoteDrive As String, Optional Username As String, Optional Password As String) As Boolean

Dim NetR As NETCONNECT

NetR.dwScope = RESOURCE_GLOBALNET

NetR.dwType = RESOURCETYPE_DISK

NetR.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE

NetR.dwUsage = RESOURCEUSAGE_CONNECTABLE

NetR.lpLocalName = Left$(LocalDrive, 1) & ":"

NetR.lpRemoteName = RemoteDrive

MapDrive = (WNetAddConnection2(NetR, Username, Password, CONNECT_UPDATE_PROFILE) = 0)

End Function

Private Sub Command1_Click()

If MapDrive("I:", Text1.Text) Then

MsgBox "映射网络驱动器成功"

Else

MsgBox "映射网络驱动器失败"

End If

End Sub
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: