专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > VB Dotnet

100分请问怎样在VB.NET中获得UNC路径,(顶者有分)

发布时间:2011-06-23 15:59:32 文章来源:www.iduyao.cn 采编人员:星星草
100分请教怎样在VB.NET中获得UNC路径,急!!!(顶者有分)
1、请问能否不用API获取UNC路径,如果可以请帮忙。

2、如果只能用API获取UNC路径,请问如何获得。

各位高手,拜托啦。


------解决方案--------------------
to 2、如果只能用API获取UNC路径,请问如何获得。

Network Shares and UNC paths
http://www.codeproject.com/cs/internet/networkshares.asp
------解决方案--------------------
http://www.vbgood.com/vb.good/article-do-view-articleid-2775.html
------解决方案--------------------
http://www.songbai.com/vb/vbart/200606/vb_8473.html
这个上面有
------解决方案--------------------
ding qi
------解决方案--------------------
API的代码在.NET下也是能用的,很多API都还是用以前VB6老的方法
------解决方案--------------------
不会,但帮忙顶
------解决方案--------------------
帮你顶!
------解决方案--------------------
Get the UNC Path

Networked drives. They注释:re an administrative nightmare. In fact, the average user changes his networked drive letters more often than his underwear.


But you can solve this problem of binding an application to a particular drive by using a Universal Naming Convention (UNC) path(UNC(Universal Naming Conversion)通用命名标准。). This still references a network area, but doesn抰 tie it to any one drive letter.

And you can retrieve and check the UNC of a particular path in code using this neat little function.

To use it, simply call GetUNCPath, passing it your drive letter along with a pre-declared empty string. If a problem occurs, the relevant number is passed back with the function. These can be matched with the possible return code constants.

However if everything goes swimmingly, the function returns a zero (a constant value of NO_ERROR) and places the UNC path into the ByRef-passed variable.

This code works by making a call to the WNetGetConnection function in MPR.DLL. It注释:s essentially a neat wrapper for a regular API call.

Usage

Dim strUNC As String

If GetUNCPath( "H: ", strUNC) = NO_ERROR Then
MsgBox "The UNC of the specified drive is " & strUNC
Else
MsgBox "There was a problem, sorry! "
End If
Code

注释: To be put inside a module

注释:Possible return codes from the API
Public Const ERROR_BAD_DEVICE As Long = 1200
Public Const ERROR_CONNECTION_UNAVAIL As Long = 1201
Public Const ERROR_EXTENDED_ERROR As Long = 1208
Public Const ERROR_MORE_DATA As Long = 234
Public Const ERROR_NOT_SUPPORTED As Long = 50
Public Const ERROR_NO_NET_OR_BAD_PATH As Long = 1203
Public Const ERROR_NO_NETWORK As Long = 1222
Public Const ERROR_NOT_CONNECTED As Long = 2250
Public Const NO_ERROR As Long = 0

注释:This API returns a UNC from a drive letter
Declare Function WNetGetConnection Lib "mpr.dll " Alias _
"WNetGetConnectionA " _
(ByVal lpszLocalName As String, _
ByVal lpszRemoteName As String, _
cbRemoteName As Long) As Long

Function GetUNCPath(ByVal strDriveLetter As String, _
ByRef strUNCPath As String) As Long

On Local Error GoTo GetUNCPath_Err

Dim strMsg As String
Dim lngReturn As Long
Dim strLocalName As String
Dim strRemoteName As String
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: