none
Could not access network drive when Impersonating.

    Question

  • I wonder if it is a bug or something wrong with the following C# console app.  Without impersonation, everything works as expected. But if impersonating, even the impersonated identity is the same as logon user, it still could not access any files on the network drive.

     

    It does not repro with physical drives like (C:\ or D:\ ).

     

    Is there anyone who knows the answer? Thanks a lot!

     

     

    WindowsIdentity wid;
      WindowsImpersonationContext impersonatedUser;

     

    wid=IniIdentity(); // wid get a Domain account identity which has access to the network drive here

    impersonatedUser = wid.Impersonate();

     

    // Do something here, all file/directory access to network drives (like "Z:\....") failed.

     

    impersonatedUser.Undo();


     

    Monday, July 09, 2007 4:51 AM

Answers

  • The Remarks section in this MSDN library article is relevant.  Not much you can do I fear but reference the network shares by their share name rather than a mapped network drive letter.  Remapping the drive letters with WNetUseConnection() seems a bit pointless.
    Monday, July 09, 2007 4:15 PM
    Moderator

All replies

  • The Remarks section in this MSDN library article is relevant.  Not much you can do I fear but reference the network shares by their share name rather than a mapped network drive letter.  Remapping the drive letters with WNetUseConnection() seems a bit pointless.
    Monday, July 09, 2007 4:15 PM
    Moderator
  • Unfortunately I could not use a UNC share to access because it’s too long (over 260 characters which is the limit of system & .NetFx). That’s why I turned to “mapping network drive” for help. :-(

     

    Tuesday, July 10, 2007 2:30 AM