Bonjour,
J'utilise une petite routine (pas à moi) pour obtenir les infos sur mes cartes réseaux. Mais sur certains PC ça ne donne rien (juste "ligne trop longue")
Cette procédure était nickel ()
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 var Error, BufLen : DWORD; P : Pointer; AdapterInfo : PTIP_ADAPTER_INFO; Descr, LocalIP, GatewayIP, DHCPIP : string; i : integer; begin i:=1; if not Assigned( List ) then EXIT; List.Clear; BufLen := SizeOf( AdapterInfo^ ); New( AdapterInfo ); Error := GetAdaptersInfo( AdapterInfo, @BufLen ); P := AdapterInfo; if Error = NO_ERROR then begin while P <> nil do with TIP_ADAPTER_INFO(P^) do begin SetLength( Descr, SizeOf( Description ) ); Descr := Trim( string( Description ) ); // if IPAddressList.IpAddress[1] <> #0 then LocalIP := IPAddressList.IpAddress else LocalIP := NULL_IP; // if GateWayList.IPAddress[1] <> #0 then GateWayIP := GatewayList.IPAddress else GateWayIP := NULL_IP; // if DHCPServer.IPAddress[1] <> #0 then DHCPIP := DHCPServer.IPAddress else DHCPIP := NULL_IP; {if mac=MacAddr2Str( TMacAddress( Address ), AddressLength )then result:=GatewayIP; } if GatewayIP<>'0.0.0.0' then begin dans_tableau(MacAddr2Str( TMacAddress( Address ), AddressLength ),'Mac #'+inttostr(i)); dans_tableau(GatewayIP,'IP #'+inttostr(i)); dans_tableau(Descr,'Type #'+inttostr(i)); dans_tableau(dhcp(MacAddr2Str( TMacAddress( Address ), AddressLength )),'DHCP #'+inttostr(i)); dans_tableau(vitesse (MacAddr2Str( TMacAddress( Address ), AddressLength )),'Vitesse #'+inttostr(i)); inc(i); end; List.Add( Descr ); List.Add( Format( '%8.8x|%6s|%16s|%2d|%16s|%16s|%16s', [Index, AdaptTypes[aType], MacAddr2Str( TMacAddress( Address ), AddressLength ), DHCPEnabled, LocalIP, GatewayIP, DHCPIP] ) ); List.Add( ' ' ); P := Next; // TIP_ADAPTER_INFO(P^).Next points to next entry end // with end // while else List.Add( SysErrorMessage( Error ) ); Dispose( AdapterInfo );
Bon je ne laisse pas tomber alors je cherche avec les WMI et j'ai bien trouvé mais c'est vraiment moins bien et aussi ça marche pas à tous les coups.
J'avais tout d'abord utilisé IPConfig/all (procédure pas à moi non plus) avec Delphi et parfois ça faisait planter le PC pas de résultat rien ()
Voila donc ma situation, je cherche une méthode qui marche à tous les coups pour obtenir pour toutes les cartes réseaux son adresse MAC, son modèle, son adresse IP et si elle est en DHCP ou non.
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 const ReadBuffer = 2400; var Security : TSecurityAttributes; ReadPipe,WritePipe : THandle; start : TStartUpInfo; ProcessInfo : TProcessInformation; Buffer : Pchar; BytesRead,Apprunning: DWord; begin jauge.Position:=0; With Security do begin nlength := SizeOf(TSecurityAttributes); binherithandle := true; lpsecuritydescriptor:= nil; end; if Createpipe (ReadPipe, WritePipe,@Security, 0) then begin Buffer := AllocMem(ReadBuffer + 1); FillChar(Start,Sizeof(Start),#0); start.cb := SizeOf(start); start.hStdOutput := WritePipe; start.hStdInput := ReadPipe; start.dwFlags := STARTF_USESTDHANDLES +STARTF_USESHOWWINDOW; start.wShowWindow := SW_HIDE; if CreateProcess(nil,PChar('cmd /C ipconfig/all'),@Security,@Security,true,NORMAL_PRIORITY_CLASS,nil,nil,start,ProcessInfo) then begin repeat Apprunning := WaitForSingleObject(ProcessInfo.hProcess,100); jauge.Position:=jauge.Position+1; if jauge.Position=100 then jauge.Position:=0; Application.ProcessMessages; until (Apprunning <> WAIT_TIMEOUT); repeat BytesRead := 0; ReadFile(ReadPipe,Buffer[0], ReadBuffer,BytesRead,nil); Buffer[BytesRead]:= #0; OemToAnsi(Buffer,Buffer); AMemo.Text := AMemo.text + String(Buffer); until (BytesRead < ReadBuffer); end; FreeMem(Buffer); CloseHandle(ProcessInfo.hProcess); CloseHandle(ProcessInfo.hThread); CloseHandle(ReadPipe); CloseHandle(WritePipe); end; jauge.Position:=0;
Ou savoir pourquoi ça marche ou pas
Merci d'avance de votre aide et vos lumières
Partager