• 0

[C#] User credentials error for local connections


Question

Can anyone tell me why my program thinks I am trying to make a local connection when I set the machine name value to a remote host (i.e. not localhost)

private void cmdGo_Click(object sender, System.EventArgs e)	{

	treeControl.Nodes.Clear();
	String machineName = txtMachineName.Text;

	if (machineName.CompareTo("localhost") == 0) {
 ?// do nothing with connection options as this is a local connection
	} else {
 ?objectConnection.Username = txtUsername.Text;
 ?objectConnection.Password = txtPassword.Text;
	}

	objectManagementScope = new ManagementScope("\\\\" + machineName, objectConnection);

	try {
 ?objectManagementScope.Connect();
	} 
	catch (System.Exception ex) {
 ?MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
	}
etc...

When the code reaches the ".Connect();" part I get this error message:

"User credentials cannot be used for local connections"

See the end of this message for details on invoking

just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************

System.Management.ManagementException: User credentials cannot be used for local connections

at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)

at System.Management.ManagementScope.InitializeGuts()

at System.Management.ManagementScope.Initialize()

at System.Management.ManagementObjectSearcher.Initialize()

at System.Management.ManagementObjectSearcher.Get()

at WMI_Windows_App.frmMain.getDiskInfo() in c:\documents and settings\mark\my documents\visual studio projects\behind the minority report\main.cs:line 318

at WMI_Windows_App.frmMain.cmdGo_Click(Object sender, EventArgs e) in c:\documents and settings\mark\my documents\visual studio projects\behind the minority report\main.cs:line 269

at System.Windows.Forms.Control.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnClick(EventArgs e)

at System.Windows.Forms.Button.PerformClick()

at System.Windows.Forms.Button.ProcessMnemonic(Char charCode)

at System.Windows.Forms.Control._ProcessMnemonic(Char charCode)

at System.Windows.Forms.ContainerControl.ProcessMnemonic(Char charCode)

at System.Windows.Forms.ContainerControl.ProcessDialogChar(Char charCode)

at System.Windows.Forms.Control.ProcessDialogChar(Char charCode)

at System.Windows.Forms.Control.ProcessDialogChar(Char charCode)

at System.Windows.Forms.Control.PreProcessMessage(Message& msg)

at System.Windows.Forms.ThreadContext.System.Windows.Forms.UnsafeNativeMethods+IMsoComponent.FPreTranslateMessage(MSG& msg)

2 answers to this question

Recommended Posts

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.