【发布时间】:2011-07-10 04:31:21
【问题描述】:
我想获得用户系统上可用的 activeX 控件的完整列表。就像你想要导入一个activeX 时delphi 所做的一样。 (它显示一个列表)
问候, 贾维德
【问题讨论】:
-
我想用 Delphi 来做这件事。我想用编码来做,而不是通过外部的东西。
-
它看起来确实是个骗子,但来自不同的question。从好的方面来说,这确实回答了你的问题!
我想获得用户系统上可用的 activeX 控件的完整列表。就像你想要导入一个activeX 时delphi 所做的一样。 (它显示一个列表)
问候, 贾维德
【问题讨论】:
这是您(几乎)想要的 c++ 版本。您将获得所有课程的列表。猜测 Delphi 中的 ActiveX 导入向导对于每个库都有一行。 How to list all installed ActiveX controls?
在 Delphi 中你可以做这样的事情。
const
CATID_Control: TGUID = '{40FC6ED4-2438-11cf-A3DB-080036F12502}';
procedure GetActiveXControlList(List: TStringList);
var
catInfo: ICatInformation;
enumGuid: IEnumGUID;
ClassID: TGUID;
Fetched: Cardinal;
Name: PWideChar;
begin
OleCheck(CoCreateInstance(CLSID_StdComponentCategoryMgr, nil,
CLSCTX_INPROC_SERVER, ICatInformation, CatInfo));
catInfo.EnumClassesOfCategories(1, @CATID_Control, 0, @GUID_NULL, EnumGUID);
while enumGuid.Next(1, ClassID, Fetched) = S_OK do
begin
OleCheck(OleRegGetUserType(ClassID, USERCLASSTYPE_FULL, Name));
List.Add(Name);
end;
end;
【讨论】:
这几乎是PowerShell solution from Jeff Atwood 的直接端口:
procedure GetActiveXObjects( strings : TStrings );
const
BASE_KEY = '\Software\Classes';
var
reg : TRegistry;
keys : TStrings;
regex : TPerlRegEx;
key : String;
begin
strings.Clear;
keys := nil;
regex := nil;
reg := TRegistry.Create;
try
reg.RootKey := HKEY_LOCAL_MACHINE;
reg.OpenKeyReadOnly( BASE_KEY );
keys := TStringList.Create;
reg.GetKeyNames( keys );
regex := TPerlRegEx.Create;
regex.RegEx := '^\w+\.\w+$';
for key in keys do
begin
regex.Subject := key;
if regex.Match and reg.KeyExists( BASE_KEY + '\' + key + '\CLSID' ) then
strings.Add( key )
end;
finally
reg.Free;
keys.Free;
regex.Free;
end;
end;
【讨论】:
这是我自己写的。只需添加Registry 单元即可完成!
procedure GetActiveXObjects(List: TStringList);
procedure KeyNotFound;
begin
raise exception.create('Key not found.');
end;
const
PATH = 'Software\\Classes\\TypeLib\\';
var
R: TRegistry;
S1, S2: TStringList;
S, Output: String;
begin
List.Clear;
try
S1 := TStringList.Create;
S2 := TStringList.Create;
R := TRegistry.create(KEY_READ);
R.RootKey := HKEY_LOCAL_MACHINE;
if (not R.OpenKey(PATH, False)) then
KeyNotFound;
R.GetKeyNames(S1);
for S in S1 do begin
// Position: CLSID
R.CloseKey;
if (not R.OpenKeyReadOnly(PATH + S + '\\')) then
Continue;
R.GetKeyNames(S2);
// Position:Version
if (S2.Text = '') or (not R.OpenKeyReadOnly(S2.Strings[0])) then
Continue;
Output := R.ReadString('');
if Output <> '' then
List.Add(Output);
end;
finally
R.Free;
S1.Free;
S2.Free;
end;
end;
【讨论】: