forked from adamdriscoll/PoshInternals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActivationContext.ps1
56 lines (50 loc) · 1.34 KB
/
ActivationContext.ps1
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
<#
.Synopsis
Enters a Windows Activation Context.
.DESCRIPTION
Enters a Windows Activation Context. This cmdlet accepts an activation manifest
that allows for registry free COM activation.
.EXAMPLE
Enter-ActivationContext -Manifest C:\IE.Manifest
#>
function Enter-ActivationContext
{
# The manifest to use for registry free COM activation
[CmdletBinding()]
param(
[Parameter(Manadatory)]
$manifest
)
End
{
if (-not (Test-Path $Manifest))
{
Write-Error "$Manifest does not exist"
return
}
if ($global:ActivationContext -ne $null)
{
Write-Error "Already in an activation context."
return
}
$global:ActivationContext = New-Object PoshInternals.ActivationContext
$global:ActivationContext.CreateAndActivate($manifest)
}
}
<#
.Synopsis
Exits a Windows activation context.
.DESCRIPTION
Exits a Windows activation context that was opened by Enter-ActivationContext.
.EXAMPLE
Exit-ActivationContext
#>
function Exit-ActivationContext
{
if ($global:ActivationContext -eq $null)
{
Write-Warning "Not currently within an activation context."
return
}
$global:ActivationContext.DeactivateAndFree()
}