如何检测声卡和网卡的存在 ( 积分: 200 )

  • 主题发起人 主题发起人 sunzhanwei
  • 开始时间 开始时间
S

sunzhanwei

Unregistered / Unconfirmed
GUEST, unregistred user!
[blue]如何检测声卡和网卡的存在并取得相关信息<br>顺便问一下如何检测鼠标和键盘的存在[/blue]
 
[blue]如何检测声卡和网卡的存在并取得相关信息<br>顺便问一下如何检测鼠标和键盘的存在[/blue]
 
检测声卡<br> &nbsp; uses mmsystem;<br> &nbsp; procedure TForm1.FormCreate(Sender: Tobject);<br> &nbsp; var<br> &nbsp; &nbsp; I,J: Integer;<br> &nbsp; begin<br> &nbsp; &nbsp; I: := auxGetNumDevs();<br> &nbsp; &nbsp; J: := WaveOutGetNumDevs;<br> &nbsp; &nbsp; if (I &gt; 0) or (J &gt; 0) then<br> &nbsp; &nbsp; &nbsp; &nbsp;ShowMessage('Found')<br> &nbsp; &nbsp; else<br> &nbsp; &nbsp; &nbsp; &nbsp;ShowMessage('Not Found');<br> &nbsp; end;<br><br>暫時只找到這個, 只能幫您這麼多, sorry !
 
检测声卡:<br>首先需要在uses部分加入mmsystem ,接着在窗体创建时检测声卡:<br>procedure TForm1.FormCreate(Sender: TObject); <br>var i:Integer; <br>begin <br> &nbsp;i := auxGetNumDevs(); <br> &nbsp;if i&lt;= then <br> &nbsp;label1.Caption :=系统没有发现声卡; <br>end;
 
检测声卡:<br>首先需要在uses部分加入mmsystem ,接着在窗体创建时检测声卡:<br>procedure TForm1.FormCreate(Sender: TObject);<br>var<br> &nbsp;I:Integer;<br>begin<br> &nbsp;I := auxGetNumDevs();<br> &nbsp;if I&lt;0 then<br> &nbsp; &nbsp;label1.Caption :='系统没有发现声卡'<br> &nbsp;else<br> &nbsp; &nbsp;label1.Caption:='系统有声卡';<br>end;<br><br>end.
 
检测声卡:<br>首先需要在uses部分加入mmsystem ,接着在窗体创建时检测声卡:<br>procedure TForm1.FormCreate(Sender: TObject);<br>var<br> &nbsp;I,S:Integer;<br>begin<br> &nbsp;I := auxGetNumDevs();<br> &nbsp;S:= WaveOutGetNumDevs;<br> &nbsp;if (I&gt;0) or (S&gt;0) then<br> &nbsp; &nbsp;label1.Caption:='系统有声卡'<br> &nbsp;else<br> &nbsp; &nbsp;label1.Caption :='系统没有发现声卡';<br>end;<br><br>end.<br>刚才的那个是错的。 &nbsp;不好意思啦。
 
{ <br>如果鼠标存在程序返回true <br>} <br><br>function MousePresent : Boolean; <br>begin <br> &nbsp;if GetSystemMetrics(SM_MOUSEPRESENT) &lt;&gt; 0 then <br> &nbsp; &nbsp;Result := true <br> &nbsp; else <br> &nbsp; &nbsp;Result := false; <br>end;
 
//获取网卡信息<br><br>unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls;<br><br>const<br>NULL_IP='0.0.0.0';<br>AdaptTypes : array[0..6] of string[10] =('other','ethernet','tokenring', 'FDDI', 'PPP', 'loopback', 'SLIP' );<br>type<br>TMacAddress = array[1..8] of byte;<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;Memo1: TMemo;<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>PTIP_ADDRESS_STRING = ^TIP_ADDRESS_STRING;<br>TIP_ADDRESS_STRING = array[0..15] of char; // IP as string<br>//<br>PTIP_ADDR_STRING = ^TIP_ADDR_STRING;<br>TIP_ADDR_STRING = packed record // for use in linked lists<br>Next: PTIP_ADDR_STRING;<br>IpAddress: TIP_ADDRESS_STRING;<br>IpMask: TIP_ADDRESS_STRING;<br>Context: DWORD;<br>end;<br><br>TTIME_T = array[1..325] of byte; // hack! MS time.h missing!<br><br>PTIP_ADAPTER_INFO = ^TIP_ADAPTER_INFO;<br>TIP_ADAPTER_INFO = packed record<br>Next: PTIP_ADAPTER_INFO;<br>ComboIndex: DWORD;<br>AdapterName: array[1..256 + 4] of char;<br>Description: array[1..128 + 4] of char;<br>AddressLength: UINT;<br>Address: TMacAddress;<br>Index: DWORD;<br>aType: UINT;<br>DHCPEnabled: UINT;<br>CurrentIPAddress: PTIP_ADDR_STRING;<br>IPAddressList: TIP_ADDR_STRING;<br>GatewayList: TIP_ADDR_STRING;<br>DHCPServer: TIP_ADDR_STRING;<br>HaveWINS: BOOL;<br>PrimaryWINSServer: TIP_ADDR_STRING;<br>SecondaryWINSServer: TIP_ADDR_STRING;<br>LeaseObtained: TTIME_T; //??<br>LeaseExpires: TTIME_T; //??<br>end;<br><br>function GetAdaptersInfo( pAdapterInfo: PTIP_ADAPTER_INFO;pOutBufLen: PULONG ): DWORD;stdcall; external 'IPHLPAPI.DLL';<br><br><br>var<br> &nbsp;Form1: TForm1;<br><br>implementation<br><br>uses Unit2;<br><br>{$R *.dfm}<br><br><br>function MAC2String(mac:TMacAddress;macLen:integer):String;<br>var<br>i:integer;<br>begin<br>if macLen=0 then<br>begin<br>Result := '00-00-00-00-00-00';<br>EXIT;<br>end else Result := '';<br>for i:=1 to MACLen do result:=result+format('%2.2X-',[MAC]);<br>delete(result,length(result),1);<br>end;<br><br>procedure Get_AdaptersInfo( List: TStrings );<br>var<br>Error,<br>BufLen : DWORD;<br>P : Pointer;<br>AdapterInfo : PTIP_ADAPTER_INFO;<br>Descr,<br>LocalIP,<br>GatewayIP,<br>DHCPIP : string;<br>begin<br>if not Assigned( List ) then EXIT;<br>List.Clear;<br>BufLen := SizeOf( AdapterInfo^ );<br>New( AdapterInfo );<br>Error := GetAdaptersInfo( AdapterInfo, @BufLen );<br>P := AdapterInfo;<br>if Error = NO_ERROR then<br>begin<br>while P &lt;&gt; nil do<br>with TIP_ADAPTER_INFO(P^) do<br>begin<br>SetLength( Descr, SizeOf( Description ));<br>Descr := Trim( string( Description ) );<br><br>if IPAddressList.IpAddress[1] &lt;&gt; #0 then LocalIP := IPAddressList.IpAddress<br>else LocalIP := NULL_IP;<br><br>if GateWayList.IPAddress[1] &lt;&gt; #0 then GateWayIP := GatewayList.IPAddress<br>else GateWayIP := NULL_IP;<br><br>if DHCPServer.IPAddress[1] &lt;&gt; #0 then DHCPIP := DHCPServer.IPAddress<br>else DHCPIP := NULL_IP;<br><br>List.Add( Descr );<br>list.Add(' 索引 | 类型 | MAC 地址 |DHCP| IP 地址 | 网关 IP | DHCP_IP');<br>List.Add( Format('%8.8x|%6s|%16s| %2d |%16s|%16s|%16s',[Index, AdaptTypes[aType],<br>Mac2String(TMacAddress(Address),AddressLength),DHCPEnabled, LocalIP, GatewayIP, DHCPIP]));<br>List.Add(' ');<br>P := Next; // TIP_ADAPTER_INFO(P^).Next points to next entry<br>end // with<br>end // while<br>else<br>List.Add( SysErrorMessage( Error ) );<br>Dispose( AdapterInfo );<br>end;<br><br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> &nbsp;Get_AdaptersInfo(Memo1.Lines);<br>end;<br><br>end.
 
感谢各位的答复<br>谢谢了<br>希望下次,还会得到你们的帮助
 
多人接受答案了。
 
后退
顶部