c# - Function call could not be evaluated timed out -
I wrote some basic code in C. such as:
// connection credentials remote Computer - If access to connection options in the log in account does not require oConn = new ConnectionOptions (); OConn.Username = ""; OConn.Password = ""; System.Management.ManagementScope Om = New System.Management. Management Interview ("\\ MachineX", oConn); // Organize fixed disk statistics. Management. Object highlight = new system Management. Object ("Choose the name from the FreeSpace, size, Win32_LogicalDisk, where DriveType = 3"); // Execute the query management object explorers oSearcher = new management object finder (om, oclair); // Get Results Management Object Collection oReturnCollection = oSearcher.Get (); // found the loop and information foreach (ManagementObject oReturn in oReturnCollection) through the drive found {// disc name console. WriteLine ("name:" + OReturn ["name"]. ToString ()); // Free space in the bytes console Veedline ("Free Space:" + Autern ["FreeSpace"]. Toasting ()); // shape bytes console. Wrightite ("Size:" + OReturn ["Size"]. ToString ()); }
Where the user names and passwords are made available as credentials for my local desktop account.
When I go to that line where the ManagementObjectSearcher () method of ManagementObjectColonation is obtained, I get an error (at runtime) when I try to evaluate this line, the time of the function call Ends (the last line before the foreach loop).
There is no exception, so no more details error.
How can I fix this? The code looks fine to me? This code is on another machine, so I'm using code from here (too much according to one step):
thanks
I get an exception when your code is running as it is:
System.Management.ManagementException was assigned message = "User credentials Can not be used for local connection "source =" System.Management "...
It is raised on the line where oSearcher.Get () is used, but The problem is the WMI connection, because the local computer is attempted to connect. If you add this line after the start of the OM:
console WrightLine (oMs.Path.Path);
The output will be like this (with the same exception as before):
\. \ MachineX
Then your path is interpreted as a WMI namespace named Machine X on the local (dot) machine. This is due to C # escaping rules - you can use it because of the initialization of ohm (without oakon) because credentials can not be used for local WMI connection):
System.Management.ManagementScopeOm = New System.Management.ManagementScope ("\\ root \\ cimv2");
and you will be connected to the root \ Cimv2 namespace locally. This is a good practice to use the fully complete WMI path:
System.Management.ManagementScope om = new system. Management. ManagementScope (@ "\\ MachineX \ root \ cimv2", oConn);
Comments
Post a Comment