Hi all,

I am writing one application using c# in which firstly I m getting impersonating the user and then i want to retrieve mapped Drives.

But issue is when I am calling method in following sequence:
1. create object of class
2. call mappeddrives() method
3. call impersonate method

then its working fine.
But if i m calling impersonate method before calling mappeddrives() then its not giving me list of mapped drives.

my code for getting mapped drives is :

public string MappedDrives()
            string drives = "";
            DriveInfo[] allDrives = DriveInfo.GetDrives();

            foreach (DriveInfo dirInfo in allDrives)
                if (dirInfo.DriveType.ToString() == "Network")
                    drives += dirInfo.Name+"?";                           
           return drives;

Can anyone tell me the reason behind this?


are you sure the user that you are impersonating has permissions to the mapped drives?

try logging in as that user and seeing if the mapped drives exist

impersonating user is member of administartors group.

And also when i tried deploying that application in IIS, its not giving dmapped drives in either case(means order of calling function does not matter in case of IIS)


Um, if its not running directly in the users session then it wont have any mapped drives - as its not the same.