Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to connect remote server for windows service monitoring but getting exception "
User credentials cannot be used for local connections
".
nor sure what is wrong with the code, please help

What I have tried:

ConnectionOptions con=new ConnectionOptions();
           con.Impersonation = ImpersonationLevel.Impersonate;
           con.Authentication = AuthenticationLevel.Default;
           con.Username = "admin";
           con.Password = "pass";
           con.Authority = "ntlmdomain:ServerName";
           con.EnablePrivileges = true;


           ManagementScope scope = new ManagementScope(new ManagementPath(@"\\ServerName\root\cimv2"), con);
            scope.Connect();
            ObjectQuery query=new ObjectQuery("SELECT * FROM Win32_Service WHERE Name = 'MyService'");

            ManagementObjectSearcher searcher=new ManagementObjectSearcher(scope,query);

            foreach (ManagementObject qObj in searcher.Get())
            {
                Console.Write(qObj["Status"]);
                Console.Write(" : ");
                Console.WriteLine(qObj["Status"]);
            }
Posted
Updated 7-Sep-17 0:48am

1 solution

It appears to be a very common issue. Check out the possible solutions found via Google Search: User credentials cannot be used for local connections - Google Search[^]
 
Share this answer
 
Comments
rajgaikwad01 7-Sep-17 6:51am    
I did google but not getting proper solution
Graeme_Grant 7-Sep-17 7:00am    
I see many good answers there for you...

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900