问题描述
- vb中用代码如何将com+组件卸载?
-
'函数名称:DeleteComponent'作用:删除对应com+应用中的组件'参数:sFolder COM+目录,sFileName组件名Public Function DeleteComponent(sComFolder As String, sFileName As String) As Boolean Dim oo As Object Dim oKey As Variant Dim oComponents As Object Dim i As Integer On Error GoTo Errd oCatcol.Populate For Each oo In oCatcol If oo.name = sComFolder Then oKey = oo.Key End If Next Set oComponents = oCatcol.GetCollection("Components", oKey) oComponents.Populate If oComponents.Count > 0 Then i = 0 For Each oo In oComponents If oo.name = sFileName Then oComponents.Remove i oComponents.SaveChanges Exit For End If i = i + 1 Next End If DeleteComponent = True Exit FunctionErrd:End Function以上代码是卸载com+组件的,但是上面的sFileName 并不是dll的文件名,而是“工程名.类模块名”,我怎么才能根据dll名获得它的所有类模块名?比如说我有个编译好名为test.dll 的com+组件,本身没编译前的工程里有这三个类名clsInfo,clsUpdate,clsOther.如果是把组件手工拖到com+组件服务里面某个应用下的话就会这样展示:test.clsInfo,test.clsUpdate,test.clsOther,我想要的就是怎么才能获取这三个名称出来,用于以上的卸载
解决方案
在delphi可以这么写,你参考一下
//卸载COM+应用程序
function UnInstallCOMApplication:Boolean;stdcall;
const
SComApplicationName = '你的应用程序名';
var
COMAdminCatalog : OleVariant;
CatalogCollection : OleVariant;
i : Integer;
begin
try
COMAdminCatalog := CreateOleObject('COMAdmin.COMAdminCatalog');
CatalogCollection := COMAdminCatalog.GetCollection('Applications');
CatalogCollection.Populate;
for i := 0 to CatalogCollection.Count - 1 do
if CatalogCollection.Item[i].Name = SComApplicationName then
begin
CatalogCollection.Remove(i);
CatalogCollection.SaveChanges;
Break;
end;
Result := True;
except
Result := False;
end;
end;
解决方案二:
使用VB编写的组件注册与卸载程序
详细说明
使用VB编写的组件注册与组件卸载程序,只需点击程序中的控制按钮,即可一键实现控件的注册与卸载。程序运行“demo”文件夹中的工程,并需要注册DB_SqlSever.dll组件,打开工程文件,选择“工程”/“引用”命令,选择组件位置。
下载地址:http://code.it168.com/d-12385.shtml
解决方案三:
请问你这个名称SComApplicationName是组件的名称么?还是具体的“组件.类模块名”?
解决方案四:
我要卸载某个应用里面的组件,不是整个应用都卸掉,卸掉应用我知道写法
解决方案五:
'函数名称:DeleteComponent
'作用:删除对应com+应用中的组件
'参数:sFolder COM+目录,sFileName组件名.类模块名
Public Function DeleteComponent(sComFolder As String, sFileName As String) As Boolean
Dim oo As Object
Dim oKey As Variant
Dim oComponents As Object
Dim i As Integer
On Error GoTo Errd
oCatcol.Populate
For Each oo In oCatcol
If oo.name = sComFolder Then
oKey = oo.Key
End If
Next
Set oComponents = oCatcol.GetCollection("Components", oKey)
oComponents.Populate
If oComponents.Count > 0 Then
i = 0
For Each oo In oComponents
If oo.name = sFileName Then
oComponents.Remove i
oComponents.SaveChanges
Exit For
End If
i = i + 1
Next
End If
DeleteComponent = True
Exit Function
Errd:
End Function
我的代码是这样的,sFileName是“组件名.类模块名”来的,我不知道怎么才能根据dll文件去获取到它的所有类模块名称
解决方案六:
Somebody help?