Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Friends i want to display the list of shared folders from a remote server in a local machine but i am getting Exception(User credentials cannot be used for local connections) Any help would be appreciated .......here is my code..
Thank U...........
 

System.Management.ManagementScope ms1 = new System.Management.ManagementScope();
            
            ms1.Options.Username = "pavan";
            ms1.Options.Password = "welcome";
 
            using (System.Management.ManagementClass exportedShares = new     System.Management.ManagementClass(ms1, new ManagementPath("\\\\servername\\root\\cimv2:Win32_Share"), null))
            {
                System.Management.ManagementObjectCollection shares = exportedShares.GetInstances();
                foreach (System.Management.ManagementObject share in shares)
                {
                    Response.Write("Name: " + share["Name"].ToString());
                }
            }
Posted 12-Jun-12 23:27pm
Edited 30-Oct-12 3:07am
v11
Comments
   
You need network credentials
B.S.S Pavan Kumar at 15-Jun-12 8:37am
   
Thank U for replying ..... I ve already given ntwk credentials (in line 3 and 4) Those are the uname and pwd for the system i want to get the list of shared folders....still wat are ntwk credentials should i give there plz help me out.....
BRAHMA Brahmanand Kumar Birajdar at 15-Jun-12 10:08am
   
This statement of your is contradictory - "I ve already given ntwk credentials (in line 3 and 4) Those are the uname and pwd for the system i want to get the list of shared folders".. You need to provide the NETWORK credentials and not the SYSTEM credentials....Both of these are different.Only then it will work.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Have you tried without using the user credentials.. Just comment the userid pwd and try.. the following code works for me..
 

 
System.Management.ManagementScope ms1 = new System.Management.ManagementScope();
           // ms1.Options.Username = "";
           // ms1.Options.Password = "";
            using (System.Management.ManagementClass exportedShares = new System.Management.ManagementClass(ms1, new ManagementPath("\\\\machinename\\root\\cimv2:Win32_Share"), null))
            {
                System.Management.ManagementObjectCollection shares = exportedShares.GetInstances();
                foreach (System.Management.ManagementObject share in shares)
                {
                    Response.Write("Name: " + share["Name"].ToString());
                }
            }
 
  Permalink  
Comments
B.S.S Pavan Kumar at 19-Jun-12 0:46am
   
Yes I have already Tried it out but it Throws Access Denied Exception ()
sinhasourabh at 30-Oct-12 9:23am
   
1. Are you providing correct machine name in wmi path ?
2. Try username as domain\username
sinhasourabh at 30-Oct-12 9:32am
   
because i am getting output w/o credentials and providing correct servername
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try with this:
 
 ms1.Options.Authority = string.Format("NTLMDOMAIN:{0}", txtDomain.Text);
 ms1.Options.Impersonation = ImpersonationLevel.Impersonate;
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Nirav Prabtani 268
1 OriginalGriff 217
2 Mika Wendelius 185
3 CPallini 170
4 _Amy 170
0 Nirav Prabtani 284
1 OriginalGriff 217
2 Mika Wendelius 185
3 _Amy 170
4 Sergey Alexandrovich Kryukov 154


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 26 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100