编写映射驱动器

类别:VB语言 点击:0 评论:0 推荐:
步骤:新建一窗体form,建立两个框架frame1和frame2在frame1上建立四个标签、四个text控件和一个按钮,在frame2上建立一个标签、一个text控件和一个按钮。
  代码如下
  Option Explicit
  Private Type NETRESOURCE
  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
  Const NO_ERROR = 0
  Const CONNECT_UPDATE_PROFILE = &H1
  Const RESOURCETYPE_DISK = &H1
  Const RESOURCETYPE_PRINT = &H2
  Const RESOURCETYPE_ANY = &H0
  Const RESOURCE_CONNECTED = &H1
  Const RESOURCE_REMEMBERED = &H3
  Const RESOURCE_GLOBALNET = &H2
  Const RESOURCEDISPLAYTYPE_DOMAIN = &H1
  Const RESOURCEDISPLAYTYPE_GENERIC = &H0
  Const RESOURCEDISPLAYTYPE_SERVER = &H2
  Const RESOURCEDISPLAYTYPE_SHARE = &H3
  Const RESOURCEUSAGE_CONNECTABLE = &H1
  Const RESOURCEUSAGE_CONTAINER = &H2
  Private Declare Function WNetAddConnection2 Lib “mpr.dll” Alias _
  “WNetAddConnection2A” _
  lpNetResource As NETRESOURCE _
  ByVal lpPassword As String _
  ByVal lpUserName As String _
  ByVal dwFlags As Long  As Long
  Private Declare Function WNetCancelConnection2 Lib “mpr.dll” Alias _
  “WNetCancelConnection2A” _
  ByVal lpName As String _
  ByVal dwFlags As Long _
  ByVal fForce As Long  As Long
  Private Sub cmdConnect_Click 
  Dim NetR As NETRESOURCE
  Dim ErrInfo As Long
  NetR.dwScope = RESOURCE_GLOBALNET
  NetR.dwType = RESOURCETYPE_DISK
  NetR.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
  NetR.dwUsage = RESOURCEUSAGE_CONNECTABLE
  NetR.lpLocalName = Text10 .Text
  NetR.lpRemoteName = Text11 .Text
  ErrInfo = WNetAddConnection2NetR Text13 .Text Text12 .Text CONNECT_UPDATE_PROFILE 
  If ErrInfo = NO_ERROR Then
  MsgBox “Net connection successful” vbInformation
  Else
  MsgBox “ERROR ” & StrErrInfo  & “ - Net connection unsuccessful” _
  vbExclamation
  End If
  End Sub
  Private Sub cmdDisconnect_Click 
  Dim ErrInfo As Long
  Dim strLocalName As String
  strLocalName = Text14 .Text
  ErrInfo = WNetCancelConnection2strLocalName CONNECT_UPDATE_PROFILE False 
  If ErrInfo = NO_ERROR Then
  MsgBox “Net disconnection successful” vbInformation
  Else
  MsgBox “ERROR ” & StrErrInfo  & “ - Net disconnection unsuccessful” _
  vbExclamation
  End If
  End Sub

本文地址:http://com.8s8s.com/it/it6614.htm