Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can I specify login information within VB.Net code to allow my app to access directories/folders on another server?

Posted on 2008-10-30
3
Medium Priority
?
863 Views
Last Modified: 2012-05-05
I have the following code:

Public Class Form1
    Dim FullPath As String = "\\MyServer\C$"

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ListSubDirectories(FullPath)

    End Sub

    Public Sub ListSubDirectories(ByVal FullPath As String)
        Dim currDirectory As New IO.DirectoryInfo(FullPath)

        MsgBox(currDirectory.FullName)

        For Each subDirectory As IO.DirectoryInfo In currDirectory.GetDirectories
            ListSubDirectories(subDirectory.FullName)
        Next
    End Sub
End Class
If I specify the FullPath to be the PC I am working on, there are no issues because I am already logged in obviously. If I specify FullPath as another server, it will list the initially directory I specified, but will go no further. I receive an error message:
IOException was unhandled
Logon failure: unknown user name or bad password.
I would just like to know how to specify username and password within app. My ultimate goal is to create an app which will copy/backup specified folders/directories from specified server to another network resource, ie; another PC, Networked Hard Drive, etc.

Thanks in advance.
0
Comment
Question by:WoolfStephen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
VegasCid earned 1400 total points
ID: 22841102
Hi,

After a while studing the same situation for my job I had to use shell function in vb.net.

Both FileInfo or DirectoryInfo don`t use networkCredential object to autenticate with other computers.

You can access to other computer if your Windows have access to the other computer. You get this rights when you create a network Drive or access by using Windows Explorer and you write your credentials.

Using cmd you can create NetworkDrives with net use command. You can read about it in http://www.computerhope.com/nethlp.htm

I haven't found a direct programming solution but I've get do it with:
Dim path as string = "\\10.10.10.10\c$\test"
Dim user as string = "Domain\user"
Dim pass as string = "password"
 
Shell("NET USE " & path & " " & pass & " /USER:" & user, 0, True)
Shell("NET USE " & path & " /SAVECRED", 0, True)
 
        Dim di As New DirectoryInfo(path )
        ' Get a reference to each directory in that directory.
        Dim diArr As DirectoryInfo() = di.GetDirectories()
        ' Display the names of the directories.
        Dim dri As DirectoryInfo
        For Each dri In diArr
            Console.WriteLine(dri.Name)
        Next dri

Open in new window

0
 
LVL 1

Author Comment

by:WoolfStephen
ID: 22844921
Thanks VegasCID,
I remember writing a script for mapping a drive once that would map the drive everytime the user logged in, so this makes sense. I will give this a shot.

Thx
0
 
LVL 1

Author Closing Comment

by:WoolfStephen
ID: 31511621
Thx for your help.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question