getting mapped drives

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AnuSumesh
    New Member
    • Aug 2007
    • 96

    #1

    getting mapped drives

    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 :
    Code:
    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?

    Thanks,
    Anu
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Impersonating a user does not run their login script, where mapped drives would be created?
    Just a guess

    Comment

    • AnuSumesh
      New Member
      • Aug 2007
      • 96

      #3
      im not creating mapped drives. just retrieving the list of mapped drived.
      And one more point - when i deployed my application in IIS, its not gibving me mapped drive list in either case.

      Thanks,
      Anu

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Mapped drives are mapped when a user logs on. If the user has not logged on, the drive is not mapped.

        Comment

        • AnuSumesh
          New Member
          • Aug 2007
          • 96

          #5
          sorry i did not understand.
          u m running my application in visual studio before calling impersonate method then its giving me all mapped drives.

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            Before impersonating, it is running as the logged on user. That user's drives have been mapped since the logon script was executed

            Comment

            • AnuSumesh
              New Member
              • Aug 2007
              • 96

              #7
              but logged on user and impersonating user are same

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                Originally posted by AnuSumesh
                but logged on user and impersonating user are same
                Ok, now we're getting somewhere (although that throws my idea out the window)
                So if you are logged on as userA, you can see the drives, then you tell your program to run impersonating userA, and you cannot see the drives?
                Now I really don't know what to suggest.

                Have you tried getting the mapped drives with a WMI search?
                [code=c#]

                ManagementObjec tSearcher searcher = new ManagementObjec tSearcher("root \\CIMV2", "SELECT * FROM Win32_MappedLog icalDisk");

                [/code]

                Comment

                • AnuSumesh
                  New Member
                  • Aug 2007
                  • 96

                  #9
                  No.
                  can u give me link how to use wmi for getting mapped drives?

                  Anu

                  Comment

                  • Plater
                    Recognized Expert Expert
                    • Apr 2007
                    • 7872

                    #10
                    I recomend the WMICodeCreator tool. Very usefull and it creates sample code for you

                    Comment

                    • AnuSumesh
                      New Member
                      • Aug 2007
                      • 96

                      #11
                      i have tried with this tool also. result is same. means giving mapped drives before impersonation only.

                      Comment

                      • AnuSumesh
                        New Member
                        • Aug 2007
                        • 96

                        #12
                        I have solved by using "Win32_MappedLo gicalDisk" its working.
                        Thanks a lot.
                        But i have to try same via IIS also b'coz viz IIS nothing was working.

                        Anu

                        Comment

                        • AnuSumesh
                          New Member
                          • Aug 2007
                          • 96

                          #13
                          Can you Please help me in writing code in C# for supporting Double Byte Character support for the same application?

                          Thanks
                          Anu

                          Comment

                          • Plater
                            Recognized Expert Expert
                            • Apr 2007
                            • 7872

                            #14
                            Originally posted by AnuSumesh
                            Can you Please help me in writing code in C# for supporting Double Byte Character support for the same application?

                            Thanks
                            Anu
                            That is really a different question, but I imagine it has something to do with the declared locale and you can probably use the various UTF converters found on System.Text.Enc oder

                            Comment

                            • AnuSumesh
                              New Member
                              • Aug 2007
                              • 96

                              #15
                              Thanks for reply. I am using the same system.text.enc oding but please guide me how i can test for the same on my window xp machine (For japanese)?

                              Comment

                              Working...