1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| try {
ConnectionOptions connection = new ConnectionOptions();
connection.Username = tb_usernameX5.Text;
connection.Password = tb_passwordX5.Text;
connection.Authority = tb_domaineX5.Text;
ManagementScope scope = null;
try {
scope = new ManagementScope("\\\\" + tb_nompcX5.Text + "\\root\\CIMV2", connection);
scope.Connect();
}
catch(ExceptionQueTuVeuxCatcher f) {
MessageBox.Show(f.Message);
// return;
}
// Ici soit tu testes IsConnected, soit tu mets un return plus haut pour sortir de ta méthode (en commentaire)
if (scope != null && scope.IsConnected) {
ObjectQuery query1 = new ObjectQuery("SELECT * FROM WIN32_ComputerSystemProduct");
using (ManagementObjectSearcher searcher1 = new ManagementObjectSearcher(scope, query1)) {
foreach (ManagementObject queryObj in searcher1.Get()) {
lb_modele.Text = queryObj["name"].ToString();
lb_servtag.Text = queryObj["IdentifyingNumber"].ToString();
lb_fabricant.Text = queryObj["Vendor"].ToString();
}
}
}
}
catch (ManagementException f) {
MessageBox.Show(f.Message);
} |
Partager