我设法使用这个VB .Net代码在使用局域网的另一台计算机上读取文件untitle.txt的内容。
Dim fileReader As System.IO.StreamReader
fileReader = My.Computer.FileSystem.OpenTextFileReader("\\192.168.10.1\test\untitle.txt")
Dim stringReader As String
stringReader = fileReader.ReadLine()
MsgBox(stringReader).
但是当我使用用户名和密码读取的计算机时,如何在脚本中输入用户名和密码呢?
答案 0 :(得分:0)
你可以尝试这个,它应该有效:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim myCredentials As New NetworkCredential("", "", "")
myCredentials.Domain = "http://192.168.10.1/"
myCredentials.UserName = "admin"
myCredentials.Password = "admin"
Dim myWebRequest As WebRequest = WebRequest.Create("http://192.168.10.1/test/untitle.txt")
myWebRequest.Credentials = myCredentials
Dim httpResponse As HttpWebResponse
httpResponse = myWebRequest.GetResponse()
Dim reader As New StreamReader(httpResponse.GetResponseStream())
RichTextBox1.Text = reader.ReadToEnd
End Sub
End Class
希望它对您有用:)