how to access to a windows share with credential (VB.NET)?

alessandro belli 131 Reputation points
2021-09-14T16:01:34.637+00:00

I need to access from my code in VB.net (framework 4.5) to a network smb share on an external domain that require authentication with windows credential.
I've tryed with a code like this
Dim theNetworkCredential = New System.Net.NetworkCredential(My.Settings.username, My.Settings.password)

        Dim theNetcache = New CredentialCache

        Dim urx As New Uri("\\192.168.6.5\myshare")

        theNetcache.Add(urx, "Basic", theNetworkCredential)

        Dim theFolders() As String = System.IO.Directory.GetDirectories(My.Settings.share)

but It fail with "unknow user or wrong password"
Any Idea?
Thank you
Alex

.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,135 questions
{count} votes