在局域网中,如何读取指定IP已共享的文件夹中,子目录和文件呢???(有代码,帮瞧瞧吧。)

xymsgw 2007-09-10 03:48:01
哪位朋友帮瞧一下如下代码,当读取本地化模板时,一切正常,当把MyPath改为局域网中指定的IP电脑共享的目录时,就无法读到模板了,局域网采用的是域管理方式。用后面的ConnectServer()也无法登入,用户和密码绝对正确的,不知如何解。我的目地就是想通过IP读取网络中某台电脑已共享的目录,子目录,及文件。不知大家有什么好的方法。十分感谢!!

'Dim MyPath As String = "\\192.168.0.201\Document\模板\"
Dim MyPath As String = "D:\bin\Document\模板\"
Dim MyDirectories As String()
=================================================================

'选定模板类型。
Private Sub 模_类型_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 模_类型.SelectedIndexChanged
ReadTemplateSort()
End Sub

=================================================================

'读取所选定的 模板目录列表 到 ListBox1_模板目录列表 控件。
Private Sub ReadTemplateSort()
Dim MySubPath As String = MyPath + Me.模_类型.SelectedItem + "\"
MyDirectories = Directory.GetDirectories(MySubPath)
Dim MySubDirectories As String
For Each MySubDirectories In MyDirectories
Me.ListBox1_模板目录列表.Items.Add(MySubDirectories.Remove(0, MySubPath.Length))
Next
End Sub

=====================================================
Imports System.Management
Imports System.Net
Imports System.IO

Private Sub ConnectServer(ByVal IPAdress As String, ByVal UserName As String, ByVal Password As String)

'通过IP,用户,密码连接服务器。

Try
Dim coption As New ConnectionOptions
coption.Username = CStr(Trim(UserName))
coption.Password = CStr(Trim(Password))
Dim scope As ManagementScope
scope = New ManagementScope("\\" & CStr(Trim(IPAdress)) & "\root\cimv2", coption)
scope.Connect()

If scope.IsConnected = True Then
MsgBox("连接成功!", MsgBoxStyle.OKOnly, "提示")
End If
'Catch ex As Exception
' MsgBox("无法连接服务器。", MsgBoxStyle.OKOnly, "提示")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
...全文
397 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
headsonlkc 2007-09-12
  • 打赏
  • 举报
回复
好象可以用那个FILELIST和DRIVATELIST这个控件

16,721

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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