2014-05-19 81 views
1

如果計算機中安裝了某個供應商的特定範圍的聲卡,我想將一個功能集成到我的安裝程序中。使用Inno Setup獲取聲卡的供應商ID和設備ID

我已閱讀關於Win32_SoundDevice class,但不幸的是我不明白如何將它實現到腳本中。

有人請向我解釋如何做到這一點?

在此先感謝!

+0

通過哪個屬性(或屬性的組)的那個WMI班級你會認識到這個soudcards的範圍嗎? – TLama

+0

我認爲VendorID和DeviceID,但我只是再次查看屬性,沒有VendorID ...也許製造商和名稱/ ProductName會更好。 – user1662035

回答

1

即使我不認爲這是識別系統中是否存在某些音頻設備的可靠方法,但您可以參考這裏提供的Win32_SoundDevice WMI類的可能實現。在下面的示例中使用的查詢由給定製造商濾波器音頻設備,然後可以迭代返回的記錄,並檢查是否剛剛迭代設備相匹配的給定的產品名稱之一:

[Setup] 
AppName=My Program 
AppVersion=1.5 
DefaultDirName={pf}\My Program 

[Code] 
function IsSupportedSoundDeviceAvailable(const Vendor: string; 
    Models: TStrings): Boolean; 
var 
    I: Integer; 
    WQLQuery: string; 
    WbemLocator: Variant; 
    WbemServices: Variant; 
    WbemObjectSet: Variant; 
begin 
    Result := False; 

    WbemLocator := CreateOleObject('WbemScripting.SWbemLocator'); 
    WbemServices := WbemLocator.ConnectServer('localhost', 'root\CIMV2'); 

    WQLQuery := Format('SELECT ProductName FROM Win32_SoundDevice ' + 
    'WHERE Manufacturer = "%s"', [Vendor]); 

    WbemObjectSet := WbemServices.ExecQuery(WQLQuery); 
    // if the query returns at least one record, then... 
    if not VarIsNull(WbemObjectSet) and (WbemObjectSet.Count > 0) then 
    begin 
    // iterate each record in the recordset and if its ProductName exactly 
    // matches an item in the passed Models collection, then return True 
    for I := 0 to WbemObjectSet.Count - 1 do 
     if Models.IndexOf(WbemObjectSet.ItemIndex(I).ProductName) <> -1 then 
     begin 
     Result := True; 
     Exit; 
     end; 
    end; 
end; 

procedure InitializeWizard; 
var 
    Models: TStrings; 
begin 
    Models := TStringList.Create; 
    try 
    // fill the exact product model names into the collection 
    Models.Add('Creative AudioPCI (ES1371,ES1373) (WDM)'); 
    // call this function to determine, whether there's at least one device 
    // that matches the product name of the vendor given in the first param 
    if IsSupportedSoundDeviceAvailable('Creative Technology Ltd.', Models) then 
     MsgBox('Sound device is available.', mbInformation, MB_OK); 
    finally 
    Models.Free; 
    end; 
end; 
+0

只是一個說明,'ItemIndex'屬性不存在於Windows XP中。 – RRUZ

相關問題