We currently use an externally writen app to deliver MTS / COM + packages. There is a COMPlus table which only sets some values for pre-existing packages.
Does anyone know of a tool inside IS IDE to add COM packages from start to finish?
Thanks!
This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
COM Plus Packages
Started by
yamadharma
, Feb 01 2002 14:18
1 reply to this topic
Posted 03 May 2002 - 10:26
Use this code for COM+ registration with roles and identity defined.
#include <stdio.h>
#include "comservice.h"
#import "c:\\windows\\system32\\com\\Comadmin.dll" no_namespace
void setRoleForCom(ICatalogCollectionPtr, ICatalogObjectPtr, _bstr_t, _bstr_t, _bstr_t);
void installCom(ICOMAdminCatalogPtr, _bstr_t, _bstr_t);
void setRolesForApp(ICatalogCollectionPtr, ICatalogObjectPtr, _bstr_t);
void setConsStrForCom(ICatalogCollectionPtr, ICatalogObjectPtr, _bstr_t, _bstr_t);
//void setUsersForRole (ICatalogCollectionPtr, ICatalogObjectPtr, _bstr_t);
/*------------CHANGE THE PATH OF THE DLL BEFORE COMPILING----------------*/
#define HELLOWORLD_DLL_PATH L"C:\\CPWr_AddOn.dll"
#define PROGID L"Weycodir.weyco"
#define COMPLUSAPPNAME "WeycoDir"
#define COMPLUSUSER "Weyerhaeuser"
#define COMPLUSPASSWORD ""
#define ROLE1 L"Administrators"
#define ROLE2 L"Readers"
#define CONSTRUCTOR_STRING L"WeycoDir Application"
UINT stdcall DeleteCOMService(char szAppName[])
{
CoInitialize (NULL);
try{
ICOMAdminCatalogPtr spCatalog("COMAdmin.COMAdminCatalog");
ICatalogCollectionPtr spApplications;
ICatalogObjectPtr spHelloWorldApplication;
spApplications = spCatalog->GetCollection (L"Applications");
spApplications->Populate ();
_variant_t vntName;
_bstr_t bStr;
LONG lCount=0;
spApplications->get_Count(&lCount);
TCHAR szTempStr[100];
for(int i=0;i<lCount;i++)
{
spHelloWorldApplication = spApplications->GetItem(i);
spHelloWorldApplication->get_Value(L"Name", &vntName);
bStr=vntName;
Convert(bStr,szTempStr,100);
if(!strcmp(szTempStr,szAppName))
{
spApplications->Remove(i);
break;
}
}
spApplications->SaveChanges ();
}
catch(_com_error &e){
::MessageBox(0,(char*) e.Description(), "ERROR",0);
}
CoUninitialize ();
return 0;
}
LPTSTR Convert(BSTR pStr,LPTSTR szStr,INT nSize)
{
DWORD dwRet = WideCharToMultiByte(
CP_ACP,0,(LPCWSTR)pStr,-1,szStr,nSize,NULL,NULL);
return szStr;
}
void setRolesForApp(ICatalogCollectionPtr spApplications, ICatalogObjectPtr spApplication, _bstr_t pwszRole){
try{
ICatalogCollectionPtr spRoles;
VARIANT vntAppKey;
spApplication->get_Key (&vntAppKey);
spRoles = spApplications->GetCollection (L"Roles", &vntAppKey);
ICatalogObjectPtr spSomeRole;
spSomeRole = spRoles->Add ();
_variant_t vntRoleName(pwszRole);
spSomeRole ->put_Value (L"Name",vntRoleName);
spRoles->SaveChanges ();
}
catch(_com_error &e){
}
}
void installCom(ICOMAdminCatalogPtr spCatalog, _bstr_t pwszAppName, _bstr_t pwszPath){
int i = 0;
try{
i = spCatalog->InstallComponent(pwszAppName, pwszPath, L"", L"");
}
catch(_com_error &e){
printf("");
}
}
void setConsStrForCom(ICatalogCollectionPtr spApplications, ICatalogObjectPtr spApplication, _bstr_t pwzProgID, _bstr_t pwszConsStr){
try{
HRESULT hr;
ICatalogCollectionPtr spComponents;
VARIANT vntAppKey;
spApplication->get_Key (&vntAppKey);
spComponents = spApplications->GetCollection (L"Components", vntAppKey);
spComponents->Populate ();
ICatalogObjectPtr spComponent;
long lngCompCnt;
spComponents->get_Count (&lngCompCnt);
for(int j=0; j < lngCompCnt; j++){
IDispatch* pDispComObject;
hr = spComponents->get_Item (j,&pDispComObject);
spComponent = pDispComObject;
VARIANT vntRetName;
spComponent->get_Name(&vntRetName);
if(vntRetName.vt == VT_BSTR ){
_bstr_t pwszTemp = vntRetName.bstrVal;
if(pwzProgID == pwszTemp)
break;
}
}
_variant_t vntConStr = pwszConsStr;
_variant_t vntBool = false;
spComponent->put_Value(L"ConstructionEnabled", vntBool);
spComponent->put_Value (L"ConstructorString", vntConStr );
spComponents->SaveChanges ();
}
catch(_com_error &e){
}
}
void setRoleForCom(ICatalogCollectionPtr spApplications, ICatalogObjectPtr spApplication, _bstr_t pwzProgID, _bstr_t pwszRole, _bstr_t szUserName){
try{
HRESULT hr;
ICatalogCollectionPtr spComponents;
VARIANT vntAppKey;
spApplication->get_Key (&vntAppKey);
spComponents = spApplications->GetCollection (L"Components", vntAppKey);
spComponents->Populate ();
ICatalogObjectPtr spComponent;
long lngCompCnt;
spComponents->get_Count (&lngCompCnt);
for(int j=0; j < lngCompCnt; j++){
IDispatch* pDispComObject;
hr = spComponents->get_Item (j,&pDispComObject);
spComponent = pDispComObject;
VARIANT vntRetName;
spComponent->get_Name(&vntRetName);
if(vntRetName.vt == VT_BSTR ){
_bstr_t pwszTemp = vntRetName.bstrVal;
if(pwzProgID == pwszTemp)
break;
}
}
ICatalogCollectionPtr spRolesForObject;
spRolesForObject = spComponents->GetCollection (L"RolesForComponent", spComponent->GetKey ());
ICatalogObjectPtr spComponentRole;
spComponentRole = spRolesForObject->Add ();
_variant_t vntRoleName = pwszRole;
spComponentRole->put_Value (L"Name", vntRoleName);
spRolesForObject->SaveChanges ();
VARIANT vntBlnAccessCheck, vntAccessLevel;
vntBlnAccessCheck.vt = VT_BOOL;
vntBlnAccessCheck.boolVal = FALSE;
spApplication->put_Value (L"ApplicationAccessChecksEnabled", vntBlnAccessCheck);
vntAccessLevel.vt = VT_INT;
vntAccessLevel.intVal = 1;
spApplication->put_Value (L"AccessLevel", vntAccessLevel);
spApplications->SaveChanges ();
VARIANT vntBlnComponentCheck;
vntBlnComponentCheck.vt = VT_BOOL;
vntBlnComponentCheck.boolVal = TRUE;
spComponents->SaveChanges ();
ICatalogCollectionPtr spRoles;
spRoles = spApplications->GetCollection (L"Roles", vntAppKey);
ICatalogCollectionPtr spUsers;
VARIANT vntUserkey;
spComponentRole->get_Key(&vntUserkey);
spUsers = spRoles->GetCollection(L"UsersInRole", &vntUserkey);
ICatalogObjectPtr spSomeUser;
spSomeUser = spUsers->Add ();
_variant_t vntUserName(szUserName);
spSomeUser ->put_Value (L"User",vntUserName);
spUsers->SaveChanges ();
}
catch(_com_error &e){
}
}
#include <stdio.h>
#include "comservice.h"
#import "c:\\windows\\system32\\com\\Comadmin.dll" no_namespace
void setRoleForCom(ICatalogCollectionPtr, ICatalogObjectPtr, _bstr_t, _bstr_t, _bstr_t);
void installCom(ICOMAdminCatalogPtr, _bstr_t, _bstr_t);
void setRolesForApp(ICatalogCollectionPtr, ICatalogObjectPtr, _bstr_t);
void setConsStrForCom(ICatalogCollectionPtr, ICatalogObjectPtr, _bstr_t, _bstr_t);
//void setUsersForRole (ICatalogCollectionPtr, ICatalogObjectPtr, _bstr_t);
/*------------CHANGE THE PATH OF THE DLL BEFORE COMPILING----------------*/
#define HELLOWORLD_DLL_PATH L"C:\\CPWr_AddOn.dll"
#define PROGID L"Weycodir.weyco"
#define COMPLUSAPPNAME "WeycoDir"
#define COMPLUSUSER "Weyerhaeuser"
#define COMPLUSPASSWORD ""
#define ROLE1 L"Administrators"
#define ROLE2 L"Readers"
#define CONSTRUCTOR_STRING L"WeycoDir Application"
UINT stdcall DeleteCOMService(char szAppName[])
{
CoInitialize (NULL);
try{
ICOMAdminCatalogPtr spCatalog("COMAdmin.COMAdminCatalog");
ICatalogCollectionPtr spApplications;
ICatalogObjectPtr spHelloWorldApplication;
spApplications = spCatalog->GetCollection (L"Applications");
spApplications->Populate ();
_variant_t vntName;
_bstr_t bStr;
LONG lCount=0;
spApplications->get_Count(&lCount);
TCHAR szTempStr[100];
for(int i=0;i<lCount;i++)
{
spHelloWorldApplication = spApplications->GetItem(i);
spHelloWorldApplication->get_Value(L"Name", &vntName);
bStr=vntName;
Convert(bStr,szTempStr,100);
if(!strcmp(szTempStr,szAppName))
{
spApplications->Remove(i);
break;
}
}
spApplications->SaveChanges ();
}
catch(_com_error &e){
::MessageBox(0,(char*) e.Description(), "ERROR",0);
}
CoUninitialize ();
return 0;
}
LPTSTR Convert(BSTR pStr,LPTSTR szStr,INT nSize)
{
DWORD dwRet = WideCharToMultiByte(
CP_ACP,0,(LPCWSTR)pStr,-1,szStr,nSize,NULL,NULL);
return szStr;
}
void setRolesForApp(ICatalogCollectionPtr spApplications, ICatalogObjectPtr spApplication, _bstr_t pwszRole){
try{
ICatalogCollectionPtr spRoles;
VARIANT vntAppKey;
spApplication->get_Key (&vntAppKey);
spRoles = spApplications->GetCollection (L"Roles", &vntAppKey);
ICatalogObjectPtr spSomeRole;
spSomeRole = spRoles->Add ();
_variant_t vntRoleName(pwszRole);
spSomeRole ->put_Value (L"Name",vntRoleName);
spRoles->SaveChanges ();
}
catch(_com_error &e){
}
}
void installCom(ICOMAdminCatalogPtr spCatalog, _bstr_t pwszAppName, _bstr_t pwszPath){
int i = 0;
try{
i = spCatalog->InstallComponent(pwszAppName, pwszPath, L"", L"");
}
catch(_com_error &e){
printf("");
}
}
void setConsStrForCom(ICatalogCollectionPtr spApplications, ICatalogObjectPtr spApplication, _bstr_t pwzProgID, _bstr_t pwszConsStr){
try{
HRESULT hr;
ICatalogCollectionPtr spComponents;
VARIANT vntAppKey;
spApplication->get_Key (&vntAppKey);
spComponents = spApplications->GetCollection (L"Components", vntAppKey);
spComponents->Populate ();
ICatalogObjectPtr spComponent;
long lngCompCnt;
spComponents->get_Count (&lngCompCnt);
for(int j=0; j < lngCompCnt; j++){
IDispatch* pDispComObject;
hr = spComponents->get_Item (j,&pDispComObject);
spComponent = pDispComObject;
VARIANT vntRetName;
spComponent->get_Name(&vntRetName);
if(vntRetName.vt == VT_BSTR ){
_bstr_t pwszTemp = vntRetName.bstrVal;
if(pwzProgID == pwszTemp)
break;
}
}
_variant_t vntConStr = pwszConsStr;
_variant_t vntBool = false;
spComponent->put_Value(L"ConstructionEnabled", vntBool);
spComponent->put_Value (L"ConstructorString", vntConStr );
spComponents->SaveChanges ();
}
catch(_com_error &e){
}
}
void setRoleForCom(ICatalogCollectionPtr spApplications, ICatalogObjectPtr spApplication, _bstr_t pwzProgID, _bstr_t pwszRole, _bstr_t szUserName){
try{
HRESULT hr;
ICatalogCollectionPtr spComponents;
VARIANT vntAppKey;
spApplication->get_Key (&vntAppKey);
spComponents = spApplications->GetCollection (L"Components", vntAppKey);
spComponents->Populate ();
ICatalogObjectPtr spComponent;
long lngCompCnt;
spComponents->get_Count (&lngCompCnt);
for(int j=0; j < lngCompCnt; j++){
IDispatch* pDispComObject;
hr = spComponents->get_Item (j,&pDispComObject);
spComponent = pDispComObject;
VARIANT vntRetName;
spComponent->get_Name(&vntRetName);
if(vntRetName.vt == VT_BSTR ){
_bstr_t pwszTemp = vntRetName.bstrVal;
if(pwzProgID == pwszTemp)
break;
}
}
ICatalogCollectionPtr spRolesForObject;
spRolesForObject = spComponents->GetCollection (L"RolesForComponent", spComponent->GetKey ());
ICatalogObjectPtr spComponentRole;
spComponentRole = spRolesForObject->Add ();
_variant_t vntRoleName = pwszRole;
spComponentRole->put_Value (L"Name", vntRoleName);
spRolesForObject->SaveChanges ();
VARIANT vntBlnAccessCheck, vntAccessLevel;
vntBlnAccessCheck.vt = VT_BOOL;
vntBlnAccessCheck.boolVal = FALSE;
spApplication->put_Value (L"ApplicationAccessChecksEnabled", vntBlnAccessCheck);
vntAccessLevel.vt = VT_INT;
vntAccessLevel.intVal = 1;
spApplication->put_Value (L"AccessLevel", vntAccessLevel);
spApplications->SaveChanges ();
VARIANT vntBlnComponentCheck;
vntBlnComponentCheck.vt = VT_BOOL;
vntBlnComponentCheck.boolVal = TRUE;
spComponents->SaveChanges ();
ICatalogCollectionPtr spRoles;
spRoles = spApplications->GetCollection (L"Roles", vntAppKey);
ICatalogCollectionPtr spUsers;
VARIANT vntUserkey;
spComponentRole->get_Key(&vntUserkey);
spUsers = spRoles->GetCollection(L"UsersInRole", &vntUserkey);
ICatalogObjectPtr spSomeUser;
spSomeUser = spUsers->Add ();
_variant_t vntUserName(szUserName);
spSomeUser ->put_Value (L"User",vntUserName);
spUsers->SaveChanges ();
}
catch(_com_error &e){
}
}
Gunavelu