-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcomplus.ps1
More file actions
113 lines (94 loc) · 2.48 KB
/
complus.ps1
File metadata and controls
113 lines (94 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# This needs to be ran by a user with Admin credentials
#requires -version 4.0
#requires -runasadministrator
# Set script params
param([switch]$install, [switch]$uninstall)
<#
# Global Vars
#>
$ErrorActionPreference = "Stop"
$pkgDir = $PWD
$commonDLLs = "C\path\to\Dlls"
$comName = "com-name"
$serviceAcc = "user"
$serviceAccPass = "Password"
$compList = "$commonDLLs\file1.dll", "$commonDLLs\file2.dll", "$commonDLLs\file3.dll"
<#
# Functions
#>
Function addComPlusApp($comName, $user, $pass, $comList)
{
$comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog
$apps = $comAdmin.GetCollection(“Applications”)
$apps.Populate();
$newComPackageName = $comName
$appExistCheckApp = $apps | Where-Object {$_.Name -eq $newComPackageName}
if($appExistCheckApp)
{
Write-Host(“This COM+ Application already exists : $newComPackageName”)
}
Else
{
$newApp1 = $apps.Add()
$newApp1.Value(“Name”) = $newComPackageName
$newApp1.Value(“ApplicationAccessChecksEnabled”) = 0
$newApp1.Value(“Identity”) = $user
$newApp1.Value(“Password”) = $pass
$saveChangesResult = $apps.SaveChanges()
Write-Host(“COM+ App Created : $saveChangesResult”)
#Add Components
Write-Host("Adding Components...")
foreach($com in $comList)
{
if(Test-Path $com)
{
try
{
$comAdmin.InstallComponent($comName, $com, $null, $null)
Write-Host("$com added to $comName")
}
catch
{
$_
}
}
else
{
Write-Host("Err: File Not Found")
}
}
}
}
Function removeComPlueApp($comName)
{
$comAdmin = New-Object -ComObject COMAdmin.COMAdminCatalog
$appColl = $comAdmin.GetCollection("Applications")
$appColl.Populate()
$index = 0
foreach($app in $appColl) {
if ($app.Name -eq $comName) {
try
{
$appColl.Remove($index)
$stat = $appColl.SaveChanges()
Write-Host("Com+ App Removed: $stat")
}
catch
{
$_
}
}
$index++
}
}
<#
# Main
#>
if ($install)
{
addComPlusApp $comName $serviceAcc $serviceAccPass $compList
}
elseif ($uninstall)
{
removeComPlueApp $comName
}