Results 1 to 7 of 7

Thread: NetworkCredential help

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    NetworkCredential help

    Hi.
    I have a local computer and another computer connected to the same network but not in a domain.
    I want to access the other computer using a different username/password. An example would be, getting a list of files.
    I have created a test user account on the other computer.

    within my app, I always get the UnAuthorizedAccessException when trying to access the resource, even specifying and adding to the CredentialCache, the username/password of the account which allows access to that resource.

    can someone please tell me, how can I access a resource giving it the credential to use?

    Code:
    NetworkCredential theCredential = new NetworkCredential("test", "test");
    CredentialCache cc = new CredentialCache();
    cc.Add(@"\\computer", 135, "Basic", theCredential);
    
    string[] dirFiles = Directory.GetDirectories(@"\\computer\C");
    
    //error at the last line

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: NetworkCredential help

    ive actually gotten a step ahead now by setting some permissions again on the share, this time i get an IOException stating invalid username/password.
    However in Windows, if I access the share, I get prompted the username/password, I enter it (same as in code) and I can access it in Windows, then when I run the code again - viola - it works.
    But I want to be able to access it within code rather than authenticating in Windows giving a username/password

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: NetworkCredential help

    Try setting the Domain property of the NetworkCredential object, either directly or by passing it to the constructor.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: NetworkCredential help

    I also tried that but no luck

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  5. #5
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: NetworkCredential help

    This is what i have been trying to do as well

    did you ever have any luck with this?

  6. #6
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: NetworkCredential help

    vb Code:
    1. Dim cre As New NetworkCredential(UserName, Password)
    2.         Dim progressStep As Integer = 100 \ Receivers.Count
    3.         Dim currentProgress As Integer
    4.         uxBackWorker.ReportProgress(currentProgress)
    5.         Dim smtp As New SmtpClient(SmtpServer)
    6.         For Each rec As String In Receivers.ToArray()
    7.             Dim msg As New MailMessage(UserName, rec, Subject, Body)
    8.             For Each atta As String In Attachments.ToArray
    9.                 msg.Attachments.Add(New Attachment(atta))
    10.             Next
    11.             smtp.EnableSsl = True
    12.             smtp.Credentials = cre
    13.             smtp.Send(msg)
    14.             currentProgress += progressStep
    15.             uxBackWorker.ReportProgress(currentProgress)
    16.         Next
    This is a VB code from one of my projects it's supposed to login to mail server and send an email. I hope it's good enough for you
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  7. #7
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: NetworkCredential help

    no so much but i appreciates it

    im trying to pass credentials to a computer so i can get a list of process's from it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width