Object reference not set to an instance of an object
bonjour,
j'ai fait un script pour me récuperer l'adresse mac d'un ordinateur donné de mon réseau depuis une page aspnet.
Le code marche mais j'ai ce message d'erreur:
Citation:
Object reference not set to an instance of an object
voici le code:
Code:
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 33 34 35 36
| ConnectionOptions Options = new ConnectionOptions();
Options.Username =username;
Options.Password = userpass;
string pcName=pc name
private void ListMacAdress(string pcName, ConnectionOptions Options)
{
try
{
ManagementPath Path = new ManagementPath("\\\\" + pcName + "\\root\\cimv2");
ManagementScope MachineScope = new ManagementScope(Path, Options);
ManagementPath Query = new ManagementPath("Win32_NetworkAdapter");
ManagementObjectCollection equipCol = new ManagementClass(MachineScope, Query, null).GetInstances();
foreach (ManagementObject equip in equipCol)
{
Response.Write("Nom Equipement: " + equip["Name"] + " Adresse mac : " + equip["MacAddress"].ToString() + "</br>");
}
}
catch (Exception e)
{
Response.Write("Failed to connect to: " + pcName + "\n Error Message: " + e.Message);
}
} |
merci de m'aider à résoudre ce problème