0

I managed to read the contents of the file untitle.txt on another computer using Local Area Network using this VB .Net code.

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). 

But how about additional writing to enter the username and password into the script when the computer that I read using the username and password?

djv
  • 15,168
  • 7
  • 48
  • 72
  • 1
    Possible duplicate of [Accessing Password Protected Network Drives in Windows in C#?](https://stackoverflow.com/questions/2563724/accessing-password-protected-network-drives-in-windows-in-c) – Visual Vincent Aug 18 '17 at 12:06
  • Thank you for your answers. It looks like C # code can not run on VB .Net. I find it hard to find C # library equations for VB. Net. Hopefully there is an answer regarding this using pemprogramman vb net language. – Heru Masadi Aug 18 '17 at 12:29
  • Have you heard of a [**converter**](http://converter.telerik.com)? – Visual Vincent Aug 18 '17 at 12:33

1 Answers1

0

You can try this, it should work :

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

Hope it worked for you :)

Mousa Alfhaily
  • 1,260
  • 3
  • 20
  • 38