如何用vb建立局域网?

10个月前 (09-15 09:16)阅读7回复0
wly
wly
  • 总版主
  • 注册排名8
  • 经验值344820
  • 级别网站编辑
  • 主题68964
  • 回复0
楼主

  我想你肯定有服务器S上的治理员用户名和口令,这样你就可以先调用API建立一个IPC连接,然后你就能访问这台机器上的资源了。在你的工程中增加一个模块,该模块代码如下:Option Explicit'=====================================阐明======================================'funIpcConn(资源名,用户名,口令)建立连接'funIpcDisConn(资源名)断开连接'引用:操作系统自带的库文件 mpr。

  dll'=============================自定义常量========================================Private Const RESOURCETYPE_DISK = H1Private Const RESOURCE_GLOBALNET As Long = H2Private Const RESOURCEDISPLAYTYPE_SHARE = H3Private Const RESOURCEUSAGE_CONNECTABLE = H1'=============================自定义结构========================================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'=================================API声明=======================================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 LongPrivate Declare Function WNetCancelConnection2 Lib "mpr。

  dll" Alias "WNetCancelConnection2A" ( _ ByVal lpName As String, _ ByVal dwFlags As Long, _ ByVal fForce As Long _ ) As LongPublic Function funIpcConn(ByVal strRemoteName As String, ByVal strUserName As String, ByVal strPassword As String) As Boolean'目的:建立网络间的联系'返回: True ---- 成功' False --- 失败'注释:strRemoteName为要连接的计算机名称(如:\\HostName、\\192。

  168。199。144、\\HostName\Data)' strUserName为登录的用户名,strPassword为登录的密码 Dim NetR As NETRESOURCE NetR。

  dwScope = RESOURCE_GLOBALNET NetR。dwType = RESOURCETYPE_DISK NetR。dwDisplayType = RESOURCEDISPLAYTYPE_SHARE NetR。

  dwUsage = RESOURCEUSAGE_CONNECTABLE NetR。

  lpRemoteName = strRemoteName '建立网络映射 funIpcConn = IIf(WNetAddConnection2(NetR, strPassword, strUserName, 0) = 0, True, False)End FunctionPublic Function funIpcDisConn(ByVal strName As String) As Long funIpcDisConn = WNetCancelConnection2(strName, 0, 0) '原样返回API的返回值End Function。

0
回帖

如何用vb建立局域网? 期待您的回复!

取消