Visual Basic 2010中的地图网络驱动器 [英] Map Network Drive in Visual Basic 2010
问题描述
我现在花了几个月的时间来尝试获取有关如何映射网络驱动器,断开连接以及重新映射网络驱动器的Visual Basic 2010代码.
I have spend months now trying to get the Visual Basic 2010 codes on how to map a network drive, disconnect them, and re-map network driver.
我将需要能够将其映射到配置文件文件夹中,如下所示:
完整路径; "\ 10.10.10.12 \ Profile文件夹".
我需要登录才能访问网络文件夹/user:Domainname\UserName Password
,
然后通过消息确认映射是否成功.
I will need to be able to map it to the profile folder to something like this:
Full path; "\10.10.10.12\Profile folder".
I need to log in to have access to the network folder /user:Domainname\UserName Password
,
then confirm if mapping was successful with a message.
映射后,我将请求配置文件名称,并检查网络上是否存在该配置文件文件夹. 如果存在,则返回一条消息,指出配置文件存在,并删除覆盖所有文件夹属性(例如只读)的配置文件文件夹.
After the mapping I will request the profile name and check if such profile folder exists on the network. If it exists, return a message stating that the profile exists, and delete the profile folder overwriting any folder property like if reading only, etc.
还有其他任务,但是他是我死胡同的地方.
There are other tasks but his is where I am hit a dead end.
推荐答案
这个问题很旧,但也许OP还在寻找.我不久前写了一个HTA页面,将网络地址映射到虚拟驱动器.该代码是VBScript,因此使用WScript库,它不是VB.net的本机部分.有关更多信息,请参见 VB.Net中StackOverflow上的WScript .
This question is old but maybe the OP is still looking. I wrote an HTA page awhile back to map a network address to a virtual drive. The code is VBScript and so uses the WScript library, which is not a native part of VB.net. See WScript in VB.Net on StackOverflow for more info on that.
连接脚本:
SUB doLogOn()
Dim objNetwork, errNum, ojbFSO, strDrive, iNum
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists("\\MyServer\MyFolder\") = False Then
strDrive = "J:"
Set objNetwork = CreateObject("WScript.Network")
On Error Resume Next
objNetwork.MapNetworkDrive strDrive, "\\MyServer\MyFolder", False, "username", "password"
If Err.Number <> 0 Then
Err.Clear
End If
Set objFSO = Nothing
Set objNetwork = Nothing
End If
END SUB
就个人而言,我还没有在.Net中找到执行相同操作的代码.上面显示的VBScript很原始.我希望它以及有关绑定WScript的信息能给您带来一两个想法.
Personally, I haven't found code to do the same thing in .Net. The VBScript shown above is pretty primitive; I hope it plus the info on binding WScript gives you an idea or two, though.
这篇关于Visual Basic 2010中的地图网络驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!