Bonjour,
Nous avons développé en VBA sous Access 2003 migrée sous Access 2007, une application qui, pour un hostname netbios saisi, récolte sur le réseau l’@ mac associée.
Nous utilisons pour cela la fonction getmacaddress utilisant les commandes NBASTAT et la fonction Copymemory de la librairie kernel32 (voir la programmation plus loin)
Il semble que depuis que nous avons migré en Windows 7, cette application ne fonctionne plus; l’application se referme sur erreur.
Après test, j’ai constaté qu’elle fonctionne toujours correctement sur station XP.
J’ai essayé d’utiliser les commandes wmi en lieu et place de NBASTAT : J’obtiens une « erreur 70 permission refusée » lorsque j’essaie de collecter la mac address d’une station distante même lorsque je positionne impersonationLevel=impersonate. Sur la station hôte (« . ») la collecte est ok.
Avez-vous une solution pour obtenir les macaddress et @ip des stations distantes par programmation sous Access VBA en Windows 7 ?
Merci d’avance pour votre généreuse aide
GetMacaddress :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95 Public Function GetMACAddress(ByVal NameHost As String) As String On Error Resume Next Dim tmp As String, pASTAT As Long Dim NCB As NET_CONTROL_BLOCK, AST As ASTAT Dim NameOK As Boolean Dim t Dim octet0 As String Dim octet1 As String Dim octet2 As String Dim octet3 As String Dim octet4 As String Dim octet5 As String NCB.ncb_command = NCBRESET Call Netbios(NCB) NCB.ncb_callname = NameHost NCB.ncb_command = NCBASTAT NCB.ncb_lana_num = 0 NCB.ncb_length = Len(AST) pASTAT = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or HEAP_ZERO_MEMORY, NCB.ncb_length) If pASTAT = 0 Then Debug.Print "Erreur d'allocation memoire" Exit Function End If NCB.ncb_buffer = pASTAT Call Netbios(NCB) CopyMemory AST, NCB.ncb_buffer, Len(AST) NameOK = False For t = 0 To 5 If AST.adapt.adapter_address(t) <> 0 Then NameOK = True Exit For End If Next If NameOK = True Then octet0 = VBA.Right("0" & VBA.Hex(AST.adapt.adapter_address(0)), 2) octet1 = VBA.Right("0" & VBA.Hex(AST.adapt.adapter_address(1)), 2) octet2 = VBA.Right("0" & VBA.Hex(AST.adapt.adapter_address(2)), 2) octet3 = VBA.Right("0" & VBA.Hex(AST.adapt.adapter_address(3)), 2) octet4 = VBA.Right("0" & VBA.Hex(AST.adapt.adapter_address(4)), 2) octet5 = VBA.Right("0" & VBA.Hex(AST.adapt.adapter_address(5)), 2) tmp = octet0 & "-" & octet1 & "-" & octet2 & "-" & octet3 & "-" & octet4 & "-" & octet5 HeapFree GetProcessHeap(), 0, pASTAT GetMACAddress = tmp Else GetMACAddress = "-1" End If End Function
WMI :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
37
38
39
40
41
42
43
44 Public Function Macadresse() As String Dim computer As String Dim wmi As Object Dim vadapter As Object Dim query As Variant Dim mac As Object Dim mac_ids As String computer = "hostnamestationdistante" Set wmi = GetObject("winmgmts:\\" & computer & "\root\cimv2") 'Set wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & computer & "\root\cimv2") Set vadapter = wmi.execquery("select * from win32_networkadapterconfiguration where Ipenabled = true") For Each mac In vadapter mac_ids = mac_ids & ", " & mac.macaddress Next mac If Len(mac_ids) > 0 Then mac_ids = Mid$(mac_ids, 3) Macadresse = mac_ids End Function
Partager