Accessing a remote path?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Neural

    #1

    Accessing a remote path?


    Hi, i searched on google for a resolution for this problem but i found
    nothing interesting, i hope someone here will be able to help or at
    least hint me.

    The problem is simple: i'm trying to access a gile on a netwok PC,
    addressing it with a UNC path (ie \\servername\sh are\file.txt). I use
    the File object to do this, but i doesn't work because the remote PC
    is on another domain, and i have to provide credentials for that
    domain. I do have dose credentials, but i don't know how to use them
    in c# code. Is there a way to do this? I seached in the System.IO
    namespace, but found nothing...

    Any help will be apreciated, thanks!


    --
    NEURAL
    ggenga<at>hotma il<punto>com (ICQ: 8971364)

    'Adepto in tutte le arti, Maestro di nessuna'
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Accessing a remote path?

    Neural,

    What you need to do is imitate that person on the other domain. To do
    this, use the LogonUser API function (called through the P/Invoke layer).
    Once you have a user handle, you can impersonate that user in the current
    process by making a call to the Impersonate method on the WindowsIdentity
    class. The documentation for the Impersonate method on the WindowsIdentity
    class shows you how to do this.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Neural" <donot@spam.com > wrote in message
    news:3f951944.3 82472156@news.m icrosoft.com...[color=blue]
    >
    > Hi, i searched on google for a resolution for this problem but i found
    > nothing interesting, i hope someone here will be able to help or at
    > least hint me.
    >
    > The problem is simple: i'm trying to access a gile on a netwok PC,
    > addressing it with a UNC path (ie \\servername\sh are\file.txt). I use
    > the File object to do this, but i doesn't work because the remote PC
    > is on another domain, and i have to provide credentials for that
    > domain. I do have dose credentials, but i don't know how to use them
    > in c# code. Is there a way to do this? I seached in the System.IO
    > namespace, but found nothing...
    >
    > Any help will be apreciated, thanks!
    >
    >
    > --
    > NEURAL
    > ggenga<at>hotma il<punto>com (ICQ: 8971364)
    >
    > 'Adepto in tutte le arti, Maestro di nessuna'[/color]


    Comment

    • Neural

      #3
      Re: Accessing a remote path?

      On Tue, 21 Oct 2003 08:37:31 -0400, "Nicholas Paldino [.NET/C# MVP]"
      <mvp@spam.guard .caspershouse.c om> wrote:
      [color=blue]
      > What you need to do is imitate that person on the other domain. To do
      >this, use the LogonUser API function (called through the P/Invoke layer).[/color]

      thank you Nicholas, i'll try it.


      Comment

      • Arild Bakken

        #4
        Re: Accessing a remote path?

        "Neural" <donot@spam.com > wrote in message
        news:3f951944.3 82472156@news.m icrosoft.com...[color=blue]
        >
        > Hi, i searched on google for a resolution for this problem but i found
        > nothing interesting, i hope someone here will be able to help or at
        > least hint me.
        >
        > The problem is simple: i'm trying to access a gile on a netwok PC,
        > addressing it with a UNC path (ie \\servername\sh are\file.txt). I use
        > the File object to do this, but i doesn't work because the remote PC
        > is on another domain, and i have to provide credentials for that
        > domain. I do have dose credentials, but i don't know how to use them
        > in c# code. Is there a way to do this? I seached in the System.IO
        > namespace, but found nothing...
        >
        > Any help will be apreciated, thanks!
        >
        >
        > --
        > NEURAL
        > ggenga<at>hotma il<punto>com (ICQ: 8971364)
        >
        > 'Adepto in tutte le arti, Maestro di nessuna'[/color]

        You could also use the WNetAddConnecti on2() API to authenticate just like
        "net use" does. The drawback is that you can only authenticate as a single
        user to any given server, so you need to WNetCancelConne ction2() when done
        with the file. This might also be a problem if mulitiple processes access
        files on that server.


        Arild


        Comment

        • Neural

          #5
          Re: Accessing a remote path?

          On Tue, 21 Oct 2003 13:06:59 GMT, donot@spam.com (Neural) wrote:
          [color=blue]
          >thank you Nicholas, i'll try it.[/color]

          it worked! i had some trouble making it work, but now it's perfect!
          thank you :-)

          Comment

          Working...