0

I used a dll from this site http://www.codeproject.com/Articles/14358/User-Impersonation-in-NET
Now what I'm trying to do is to access the remote directory and get its files. Whenever i tried doing this there is no error but when I'm trying to debug it the impersonation is null and there are no token so maybe you can give me insights about this tnx!.

ImpersonateUser imp = new ImpersonateUser();
try
{
    imp.Impersonate("bla", "bla", "bla");
    try
    {
        string[] files = Directory.GetFiles(@"\\servername\folder", "*.txt");
        foreach (string file in files)
        {
            Console.WriteLine(file);

        }
    }
    catch
    {
    }
    finally
    {
    }
}
John Saunders
  • 160,644
  • 26
  • 247
  • 397
zxc
  • 1,504
  • 3
  • 13
  • 32
  • 1
    what token is 0? Why do you try to impersonate yourself on localmachine and get localfiles, but in question mentioned remote folder? – Iłya Bursov Oct 18 '13 at 02:33
  • @ilyaBursov oh i see.. what would be the proper path for the directorygetfiles? – zxc Oct 18 '13 at 02:37
  • checkout this question http://stackoverflow.com/questions/5433570/access-a-remote-directory-from-c-sharp?lq=1 – Iłya Bursov Oct 18 '13 at 02:40
  • @ilyaBursov tnx for that now Im trying to access C\test but it says network not found can you help me about this?.. – zxc Oct 18 '13 at 02:54
  • @ilyaBursov this is the format i did @"\\servername\test" still network found – zxc Oct 18 '13 at 02:57
  • my telepathy cannot reach you, how do you trying to access? did you follow instructions from answer, can you access it via windows explorer, what exactly error message and error code... – Iłya Bursov Oct 18 '13 at 03:01
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Oct 18 '13 at 03:03
  • @ilyaBursov Ok the dll that I downloaded is not working for me so i get a class instead and it shows error on unknown username of password the thing is I can see what wrong right now tnx btw – zxc Oct 18 '13 at 03:05
  • There are tons of low quality articles on CodeProject, which even fail to mention what are the permissions required by the executing account, http://msdn.microsoft.com/en-us/library/w070t6ka.aspx http://msdn.microsoft.com/en-us/library/ff647404.aspx#paght000023_impersonatingbyusingwindowsidentity – Lex Li Oct 18 '13 at 03:30

0 Answers0