Audio 使用Inno设置获取声卡的供应商ID和设备ID
我想在我的设置中集成一个功能,如果计算机中安装了某个供应商的某一系列声卡,就会安装该功能 我已经阅读了关于脚本的内容,但不幸的是,我不明白如何在脚本中实现它 谁能给我解释一下怎么做吗Audio 使用Inno设置获取声卡的供应商ID和设备ID,audio,wmi,inno-setup,Audio,Wmi,Inno Setup,我想在我的设置中集成一个功能,如果计算机中安装了某个供应商的某一系列声卡,就会安装该功能 我已经阅读了关于脚本的内容,但不幸的是,我不明白如何在脚本中实现它 谁能给我解释一下怎么做吗 提前谢谢
提前谢谢尽管我不认为这是一种可靠的方法来识别系统中是否存在某些音频设备,但这里是您提到的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;
[设置]
AppName=我的程序
AppVersion=1.5
DefaultDirName={pf}\My程序
[守则]
函数IsupportedSoundDeviceAvailable(常量供应商:字符串;
模型:TStrings):布尔型;
变量
I:整数;
WQLQuery:字符串;
WbemLocator:变体;
WbemServices:变体;
WbemObjectSet:变量;
开始
结果:=假;
WbemLocator:=CreateOleObject('WbemScripting.SWbemLocator');
WbemServices:=WbemLocator.ConnectServer('localhost','root\CIMV2');
WQLQuery:=格式('从Win32\U SoundDevice中选择产品名称'+
“其中制造商=”%s“,[Vendor]);
WbemObjectSet:=WbemServices.ExecQuery(WQLQuery);
//如果查询返回至少一条记录,则。。。
如果不是VarisAll(WbemObjectSet)和(WbemObjectSet.Count>0),则
开始
//迭代记录集中的每条记录,并检查其产品名称是否正确
//匹配传递的模型集合中的项,然后返回True
对于I:=0到WbemObjectSet.Count-1 do
如果Models.IndexOf(WbemObjectSet.ItemIndex(I).ProductName)-1,则
开始
结果:=真;
出口
结束;
结束;
结束;
程序初始化;
变量
型号:TStrings;
开始
模型:=TStringList.Create;
尝试
//在集合中填写准确的产品型号名称
型号。添加(“创造性音频PCI(ES1371、ES1373)(WDM)”;
//调用此函数以确定是否至少有一个设备
//与第一个参数中给定的供应商的产品名称匹配
如果发行支持声音设备可用(“Creative Technology Ltd.,型号”),则
MsgBox('声音设备可用'),MB信息,MB_OK);
最后
模型。免费;
结束;
结束;
您将通过WMI类的哪个属性(或属性组)识别该范围的soudcards?我认为是VendorID和DeviceID,但我只是再次查看属性,没有VendorID。。。也许制造商和名称/ProductName会更好。请注意,ItemIndex
属性在Windows XP中不存在。