找回密码
 加入
搜索
查看: 2883|回复: 7

[系统综合] WMI获取声卡设备请教

[复制链接]
发表于 2013-7-19 02:40:07 | 显示全部楼层 |阅读模式
Global $objWMIService,$colSound

Local $object,$objOperatingSystem
$objWMIService = objget("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colSound = $objWMIService.ExecQuery("Select * from Win32_SoundDevice")



For $object in $colSound
 MsgBox(0, "",$object.name)
 Next
这个代码只显示出最后一个USB声卡,如何让他默认显示板载声卡呢
发表于 2013-7-19 09:57:13 | 显示全部楼层
$sound_card = Regread("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{71A27CDD-812A-11D0-BEC7-08002BE2092F}\0000", "DriverDesc")
可以试试
发表于 2013-7-19 10:15:04 | 显示全部楼层
我这只有 ac97集成声卡  可以显示  
莫非hdaudio集成声卡 不在root\cimv2里

开个源吧以前 写过歌读取注册表硬件的

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListviewConstants.au3>
#include <EditConstants.au3>
#include <GuiListView.au3>


;定义全局常量
;------------------------------------------------------------------------------
;PCI设备注册表路径
Global Const $PciPath = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum\PCI"
;HD声卡注册表路径
Global Const $HDAudioPath = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum\HDAUDIO"

Global Const $Unkouw = "未知设备"
Global Const $VGA = "显卡"
Global Const $NET = "网卡"
Global Const $SND = "声卡"
Global Const $OTHER = "其它"
;------------------------------------------------------------------------------


;定义全局变量
;------------------------------------------------------------------------------
;存放PCI/HDAUDIO下,子键ID
Global $IDList[100]
;子键ID的子键
Global $KeyList[100]

;设备类型
Global $Class[100]
;设备描述
Global $DeviceDesc[100]
;硬件ID
Global $HardwareID[100]
;厂商代码
Global $Vendor[100]
;------------------------------------------------------------------------------


Local $window
Local $listview
Local $labletype
Local $lablehard
Local $lable
Local $edit
Local $button
Local $item[11]
Local $i

Local $width = 700
Local $hight = 500
Local $left = (@DesktopWidth - $width)/2 
Local $top = (@DesktopHeight - $hight)/2

Local $msg

$window = GUICreate("硬件ID提取工具", $width, $hight,$left, $top,$WS_MINIMIZEBOX+$WS_SIZEBOX)
GUICtrlSetFont($window,12)
$listview = GUICtrlCreateListView("类型|描述|硬件ID",10,40,680,180,-1,$LVS_EX_GRIDLINES+$LVS_EX_FULLROWSELECT)


_GUICtrlListView_SetColumnWidth($listview ,0,80)
_GUICtrlListView_SetColumnWidth($listview ,1,230)
_GUICtrlListView_SetColumnWidth($listview ,2,350)
GUICtrlSetFont($listview,12)

$labletype = GUICtrlCreateLabel("",10,240,450,25)
GUICtrlSetFont($labletype,12)

$lablehard = GUICtrlCreateLabel("",10,270,450,25)
GUICtrlSetFont($lablehard,12)

$lable = GUICtrlCreateLabel("硬件ID:",10,320,450,25)
GUICtrlSetFont($lable,12)

$edit = GUICtrlCreateEdit("",10,350,450,100,$ES_READONLY)
GUICtrlSetFont($edit,12)

$button = GUICtrlCreateButton("复制",500,350,80,40)
GUICtrlSetFont($button,12)
GUISetState(@SW_SHOW)


GUIRegisterMsg($WM_NOTIFY, "MyMsgCallBack")


ReadData()
PutData()


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
                Case $button
                    ClipPut(GUICtrlRead($edit))
                        MsgBox(64,"提示","硬件ID,已复制到剪切板!")
        EndSwitch
WEnd




Func ReadData()

Local $cnt
Local $i
Local $j

$cnt = 1
For $i = 1 to 99
    $IDList[$i] = RegEnumKey($PciPath,$i)
    If @error <> 0 then ExitLoop
    $KeyList[$i] = RegEnumKey($PciPath&"\"&$IDList[$i],1)

    $DeviceDesc[$i] = RegRead($PciPath&"\"&$IDList[$i]&"\"&$KeyList[$i],"DeviceDesc")
    $HardwareID[$i] = RegRead($PciPath&"\"&$IDList[$i]&"\"&$KeyList[$i],"HardwareID")
        $Class[$i] = RegRead($PciPath&"\"&$IDList[$i]&"\"&$KeyList[$i],"Class")
        If @error = -1 Then
                $Class[$cnt] = $Unkouw
        ElseIf $Class[$i] = "System" Or $Class[$i] = "hdc" Or $Class[$i] = "USB" Then
                ContinueLoop
        Else
        Select
            Case $Class[$i] = "Display"
                $Class[$cnt] = $VGA
            Case $Class[$i] = "Net"
                $Class[$cnt] = $NET
            Case $Class[$i] = "MEDIA"
                $Class[$cnt] = $SND
            Case Else
                $Class[$cnt] = $OTHER
        EndSelect
        EndIf
        $DeviceDesc[$cnt] = $DeviceDesc[$i]
        $HardwareID[$cnt] = $HardwareID[$i]
        $cnt += 1
Next

For $j = 1  To 10
    $IDList[$j+$i] = RegEnumKey($HDAudioPath,$j)
    If @error <> 0 then ExitLoop
    $KeyList[$j+$i] = RegEnumKey($HDAudioPath&"\"&$IDList[$j+$i],1)
    $DeviceDesc[$j+$i] = RegRead($HDAudioPath&"\"&$IDList[$j+$i]&"\"&$KeyList[$j+$i],"DeviceDesc")
    $HardwareID[$j+$i] = RegRead($HDAudioPath&"\"&$IDList[$j+$i]&"\"&$KeyList[$j+$i],"HardwareID")
    $Vendor[$j+$i] = StringMid($IDList[$j+$i],13,4)
    If $Vendor[$j+$i] = "10DE" Or $Vendor[$j+$i] = "1002" Then
        ContinueLoop
    Else
                $Class[$cnt] = $SND
                $DeviceDesc[$cnt] = $DeviceDesc[$j+$i]
                $HardwareID[$cnt] = $HardwareID[$j+$i]
        $cnt += 1
    EndIf
Next
$Class[0] = $cnt - 1 
EndFunc




Func PutData()
Local $tmp
Local $i
For $i = 1 To $Class[0]
        $HardwareID[$i] = StringAddCR($HardwareID[$i])
    $item[$i] = GUICtrlCreateListViewItem($Class[$i]&'|'&$DeviceDesc[$i]&'|'&$HardwareID[$i],$listview)
    GUICtrlSetFont($item[$i],12)
Next
_GUICtrlListView_SetItemSelected($listview,0)


GUICtrlSetData($labletype,$Class[1])
GUICtrlSetData($lablehard,$DeviceDesc[1])
$tmp = $HardwareID[1]
$tmp = StringAddCR($tmp)
GUICtrlSetData($edit,$tmp)

EndFunc

Func MyMsgCallBack($hWndGUI, $MsgID, $WParam, $LParam)
    Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
    Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
        Local $index
        Local $read[3]
        Local $i
        
    If @error Then Return $GUI_RUNDEFMSG
    $IDFrom = DllStructGetData($tagNMHDR, 2)
    $Event = DllStructGetData($tagNMHDR, 3)
    $tagNMHDR = 0
    Switch $IDFrom;选择产生事件的控件
        Case $listview
            Switch $Event; 选择产生的事件
                Case $NM_CLICK ; 左击
                    $index = _GUICtrlListView_GetSelectedIndices($listview)
                    If Not StringLen($index) Then Return; 这里用以判断是否选定了ListViewItem
                                        ;
                                        $index = Number($index)
                                        For $i = 0 To 2
                                            $read[$i] = _GUICtrlListView_GetItemText($listview, $index,$i)  
                                        Next
                                        GUICtrlSetData($labletype,$read[0])
                                        GUICtrlSetData($lablehard,$read[1])
                                        GUICtrlSetData($edit,$read[2])
                                        ;                   
                Case $NM_DBLCLK ; 双击
                Case $NM_RCLICK ; 右击
                        EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc 
发表于 2013-7-19 10:16:15 | 显示全部楼层
我这只有 ac97集成声卡  可以显示  
莫非hdaudio集成声卡 不在root\cimv2里

开个源吧以前 写过歌读取注册表硬件的

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListviewConstants.au3>
#include <EditConstants.au3>
#include <GuiListView.au3>


;定义全局常量
;------------------------------------------------------------------------------
;PCI设备注册表路径
Global Const $PciPath = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum\PCI"
;HD声卡注册表路径
Global Const $HDAudioPath = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum\HDAUDIO"

Global Const $Unkouw = "未知设备"
Global Const $VGA = "显卡"
Global Const $NET = "网卡"
Global Const $SND = "声卡"
Global Const $OTHER = "其它"
;------------------------------------------------------------------------------


;定义全局变量
;------------------------------------------------------------------------------
;存放PCI/HDAUDIO下,子键ID
Global $IDList[100]
;子键ID的子键
Global $KeyList[100]

;设备类型
Global $Class[100]
;设备描述
Global $DeviceDesc[100]
;硬件ID
Global $HardwareID[100]
;厂商代码
Global $Vendor[100]
;------------------------------------------------------------------------------


Local $window
Local $listview
Local $labletype
Local $lablehard
Local $lable
Local $edit
Local $button
Local $item[11]
Local $i

Local $width = 700
Local $hight = 500
Local $left = (@DesktopWidth - $width)/2 
Local $top = (@DesktopHeight - $hight)/2

Local $msg

$window = GUICreate("硬件ID提取工具", $width, $hight,$left, $top,$WS_MINIMIZEBOX+$WS_SIZEBOX)
GUICtrlSetFont($window,12)
$listview = GUICtrlCreateListView("类型|描述|硬件ID",10,40,680,180,-1,$LVS_EX_GRIDLINES+$LVS_EX_FULLROWSELECT)


_GUICtrlListView_SetColumnWidth($listview ,0,80)
_GUICtrlListView_SetColumnWidth($listview ,1,230)
_GUICtrlListView_SetColumnWidth($listview ,2,350)
GUICtrlSetFont($listview,12)

$labletype = GUICtrlCreateLabel("",10,240,450,25)
GUICtrlSetFont($labletype,12)

$lablehard = GUICtrlCreateLabel("",10,270,450,25)
GUICtrlSetFont($lablehard,12)

$lable = GUICtrlCreateLabel("硬件ID:",10,320,450,25)
GUICtrlSetFont($lable,12)

$edit = GUICtrlCreateEdit("",10,350,450,100,$ES_READONLY)
GUICtrlSetFont($edit,12)

$button = GUICtrlCreateButton("复制",500,350,80,40)
GUICtrlSetFont($button,12)
GUISetState(@SW_SHOW)


GUIRegisterMsg($WM_NOTIFY, "MyMsgCallBack")


ReadData()
PutData()


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
                Case $button
                    ClipPut(GUICtrlRead($edit))
                        MsgBox(64,"提示","硬件ID,已复制到剪切板!")
        EndSwitch
WEnd




Func ReadData()

Local $cnt
Local $i
Local $j

$cnt = 1
For $i = 1 to 99
    $IDList[$i] = RegEnumKey($PciPath,$i)
    If @error <> 0 then ExitLoop
    $KeyList[$i] = RegEnumKey($PciPath&"\"&$IDList[$i],1)

    $DeviceDesc[$i] = RegRead($PciPath&"\"&$IDList[$i]&"\"&$KeyList[$i],"DeviceDesc")
    $HardwareID[$i] = RegRead($PciPath&"\"&$IDList[$i]&"\"&$KeyList[$i],"HardwareID")
        $Class[$i] = RegRead($PciPath&"\"&$IDList[$i]&"\"&$KeyList[$i],"Class")
        If @error = -1 Then
                $Class[$cnt] = $Unkouw
        ElseIf $Class[$i] = "System" Or $Class[$i] = "hdc" Or $Class[$i] = "USB" Then
                ContinueLoop
        Else
        Select
            Case $Class[$i] = "Display"
                $Class[$cnt] = $VGA
            Case $Class[$i] = "Net"
                $Class[$cnt] = $NET
            Case $Class[$i] = "MEDIA"
                $Class[$cnt] = $SND
            Case Else
                $Class[$cnt] = $OTHER
        EndSelect
        EndIf
        $DeviceDesc[$cnt] = $DeviceDesc[$i]
        $HardwareID[$cnt] = $HardwareID[$i]
        $cnt += 1
Next

For $j = 1  To 10
    $IDList[$j+$i] = RegEnumKey($HDAudioPath,$j)
    If @error <> 0 then ExitLoop
    $KeyList[$j+$i] = RegEnumKey($HDAudioPath&"\"&$IDList[$j+$i],1)
    $DeviceDesc[$j+$i] = RegRead($HDAudioPath&"\"&$IDList[$j+$i]&"\"&$KeyList[$j+$i],"DeviceDesc")
    $HardwareID[$j+$i] = RegRead($HDAudioPath&"\"&$IDList[$j+$i]&"\"&$KeyList[$j+$i],"HardwareID")
    $Vendor[$j+$i] = StringMid($IDList[$j+$i],13,4)
    If $Vendor[$j+$i] = "10DE" Or $Vendor[$j+$i] = "1002" Then
        ContinueLoop
    Else
                $Class[$cnt] = $SND
                $DeviceDesc[$cnt] = $DeviceDesc[$j+$i]
                $HardwareID[$cnt] = $HardwareID[$j+$i]
        $cnt += 1
    EndIf
Next
$Class[0] = $cnt - 1 
EndFunc




Func PutData()
Local $tmp
Local $i
For $i = 1 To $Class[0]
        $HardwareID[$i] = StringAddCR($HardwareID[$i])
    $item[$i] = GUICtrlCreateListViewItem($Class[$i]&'|'&$DeviceDesc[$i]&'|'&$HardwareID[$i],$listview)
    GUICtrlSetFont($item[$i],12)
Next
_GUICtrlListView_SetItemSelected($listview,0)


GUICtrlSetData($labletype,$Class[1])
GUICtrlSetData($lablehard,$DeviceDesc[1])
$tmp = $HardwareID[1]
$tmp = StringAddCR($tmp)
GUICtrlSetData($edit,$tmp)

EndFunc

Func MyMsgCallBack($hWndGUI, $MsgID, $WParam, $LParam)
    Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
    Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
        Local $index
        Local $read[3]
        Local $i
        
    If @error Then Return $GUI_RUNDEFMSG
    $IDFrom = DllStructGetData($tagNMHDR, 2)
    $Event = DllStructGetData($tagNMHDR, 3)
    $tagNMHDR = 0
    Switch $IDFrom;选择产生事件的控件
        Case $listview
            Switch $Event; 选择产生的事件
                Case $NM_CLICK ; 左击
                    $index = _GUICtrlListView_GetSelectedIndices($listview)
                    If Not StringLen($index) Then Return; 这里用以判断是否选定了ListViewItem
                                        ;
                                        $index = Number($index)
                                        For $i = 0 To 2
                                            $read[$i] = _GUICtrlListView_GetItemText($listview, $index,$i)  
                                        Next
                                        GUICtrlSetData($labletype,$read[0])
                                        GUICtrlSetData($lablehard,$read[1])
                                        GUICtrlSetData($edit,$read[2])
                                        ;                   
                Case $NM_DBLCLK ; 双击
                Case $NM_RCLICK ; 右击
                        EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc 
 楼主| 发表于 2013-7-19 10:30:30 | 显示全部楼层
回复 2# guti_8014


找到注册表DriverDesc的值为"Generic volume"
我机器的板载声卡为ALC 892
 楼主| 发表于 2013-7-19 10:33:00 | 显示全部楼层
回复 4# veket_linux


在CIMV2里.我这里显示的一共6个声卡.第一个集成声卡ALC 892
2-5 是NVIDIA的HDMI声卡
第六个是USB通用音频.(但是我的电脑没外接任何USB声卡)
发表于 2013-7-19 12:04:17 | 显示全部楼层
nvidia 的不是声卡        是显卡的hdmi

还是注册表靠谱.....
发表于 2013-7-19 12:04:27 | 显示全部楼层
nvidia 的不是声卡        是显卡的hdmi

还是注册表靠谱.....
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-17 15:55 , Processed in 0.143149 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表