我想获得用户系统上可用的activeX控件的完整列表。就像delphi要导入activeX时的做法一样。 (它显示一个列表)
此致 Javid
答案 0 :(得分:1)
这是你想要的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;
答案 1 :(得分:1)
这几乎是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;
答案 2 :(得分:0)
这就是我自己写的。只需添加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;