Problem : Using VB.net to access files through UNC paths with specified credentials
All, I would like to try to run a program from a UNC path however i will need to use a different set of credentials to access that path how can i do that in VB.net
Solution: Using VB.net to access files through UNC paths with specified credentials
net use /user:
The you will have access to the share for that login session, or until you disconnect.
Public Shared Sub ConnectToShare(ByVal path As String, ByVal user As String, ByVal password As String)
Dim process As New System.Diagnostics.Process()
process.StartInfo = New System.Diagnostics.ProcessStartInfo(“net”)
process.StartInfo.Arguments = String.Format(“use {0} /user:””{1}”” {2}”, path, user, password)
process.Start()
process.Dispose()
End Sub
Public Shared Sub Disconnect(ByVal path As String)
Dim process As New System.Diagnostics.Process()
process.StartInfo = New System.Diagnostics.ProcessStartInfo(“net”)
process.StartInfo.Arguments = String.Format(“use /delete {0} “, path)
process.Start()
process.Dispose()
End Sub