我想得到 网 络 驱 动 器 的UNC路径 ,如何做??????

shadou 2002-06-26 03:36:03


下面有一篇文章 我做了怎么不能用???
得 到 一 个 网 络 驱 动 器 的 UNC路 径 (“ \\服 务 器 \共 享 路 径 ” )。

' 32-bit Function version.
' Enter this declaration on a single line.
Declare Function WNetGetConnection32 Lib "MPR.DLL" Alias _
"WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal _
lpszRemoteName As String, lSize As Long) As Long

' 32-bit declarations:
Dim lpszRemoteName As String
Dim lSize As Long

' Use for the return value of WNetGetConnection() API.
Const NO_ERROR As Long = 0

' The size used for the string buffer. Adjust this if you
' need a larger buffer.
Const lBUFFER_SIZE As Long = 255

Sub GetNetPath()

' Prompt the user to type the mapped drive letter.
DriveLetter = UCase(InputBox("Enter Drive Letter of Your Network" & _
"Connection." & Chr(10) & "i.e. F (do not enter a colon)"))

' Add a colon to the drive letter entered.
DriveLetter = DriveLetter & ":"

' Specifies the size in charaters of the buffer.
cbRemoteName = lBUFFER_SIZE

' Prepare a string variable by padding spaces.
lpszRemoteName = lpszRemoteName & Space(lBUFFER_SIZE)

' Return the UNC path (\\Server\Share).
lStatus& = WNetGetConnection32(DriveLetter, lpszRemoteName, _
cbRemoteName)

' Check to see if WNetGetConnection() succeeded. WNetGetConnection()
' returns 0 (NO_ERROR) if it succesfully retrieves the UNC path.
If lStatus& = NO_ERROR Then

' Display the UNC path.
MsgBox lpszRemoteName, vbInformation

Else
' Unable to obtain the UNC path.
MsgBox "Unable to obtain the UNC path.", vbInformation
End If
End Sub


这样可以吗?大家帮忙看看!!!
...全文
151 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Brunhild 2002-07-01
  • 打赏
  • 举报
回复
mark
shadou 2002-06-28
  • 打赏
  • 举报
回复
在推一推!!

up!
SuperZhou 2002-06-27
  • 打赏
  • 举报
回复
给你一个例子
Public 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

'lpPassword为远程资源的口令,lpUserName为远程资源的用户名,dwFlags标志位用于指定登录时是否重新连接
Public 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
'dwFlags设为零或CONNECT_UPDATE_PROFILE。如为零,而且建立的是永久性连接,则在windows下次重新启动时仍会重新连接
'fForce如为TRUE,表示强制断开连接(即使连接的资源上正有打开的文件或作业)
Public Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Long, ByVal fForce As Long) As Long
Public Const RESOURCETYPE_DISK = &H1
Public Const RESOURCE_GLOBALNET As Long = &H2
Public Const RESOURCEDISPLAYTYPE_SHARE = &H3
Public Const RESOURCEUSAGE_CONNECTABLE = &H1

'**********函数名:GetConn********************
'作者:
'书写日期:2002.03.28
'编辑日期:2002.03.28
'目的:建立网络间的联系
'方法:调用API函数,建立网络映射
'应用于:frmComm窗体
'注释:strRemoteName为要连接的计算机名称(如:\\zyp或\\zyp\Data),strUserName为登录的用户名,strPassword为登录的密码
'********************************************
Public Sub GetConn(ByVal strRemoteName As String, ByVal strUserName As String, ByVal strPassword As String)
Dim NetR As NETRESOURCE

NetR.dwScope = RESOURCE_GLOBALNET
NetR.dwType = RESOURCETYPE_DISK
NetR.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
NetR.dwUsage = RESOURCEUSAGE_CONNECTABLE
NetR.lpRemoteName = strRemoteName

'建立网络映射
Call WNetAddConnection2(NetR, strPassword, strUserName, 0)
End Sub

'另外断开与车道计算机的连接的语句如下
Call WNetCancelConnection2(strRemoteName, 0, True)
================================================================
共同学习,共同进步
================================================================

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧