我正在做一个小的计算机信息工具。现在我正在做用户帐户。我用可用的用户填充了一个组合框。
ManagementObjectSearcher mosAccounts = new ManagementObjectSearcher("SELECT * FROM Win32_Account");
foreach (ManagementObject moUA in mosAccounts.Get())
{
comboBox4.Items.Add(moUA["Name"].ToString());
}
然后我显示它们:
private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
{
ManagementObjectSearcher mosAccounts = new ManagementObjectSearcher("SELECT * FROM Win32_Account");
foreach (ManagementObject moUA in mosAccounts.Get())
{
lblDescriptionUA.Text = "Description: " + moUA["Description"].ToString();
if (moUA["Domain"] != null)
{
lblDomain.Text = "Domain: " + moUA["Domain"].ToString();
}
else
lblDomain.Text = "Domain: Not Available";
if (moUA["InstallDate"] != null)
{
lblInstallDateUA.Text = "Install Date: " + moUA["InstallDate"].ToString();
}
else
lblInstallDateUA.Text = "Install Date: Not Available";
lblLocalAccount.Text = "Local Account: " + moUA["LocalAccount"].ToString();
if (moUA["SID"] != null)
{
lblSID.Text = "SID: " + moUA["SID"].ToString();
}
else
lblSID.Text = "SID: Not Available";
if (moUA["SIDType"] != null)
{
lblSIDType.Text = "SID Type: " + moUA["SIDType"];
}
else
lblSIDType.Text = "SID Type: Not Available";
if (moUA["Status"] != null)
{
lblStatusUA.Text = "Status: " + moUA["Status"].ToString();
}
else
lblStatusUA.Text = "Status: Not Available";
}
}
但是每次我从组合框中选择一个用户时,标签都会变得疯狂,显示这么多信息,切换它。就像他们连续显示所有用户的信息一样。有什么我想念的吗?
附加信息:我在工作。有很多域用户。组合框将它们全部显示出来。Mybe 是因为所有的域用户。我选择了只显示本地用户,但同样的问题。