-
Notifications
You must be signed in to change notification settings - Fork 0
/
OfficeC2RCom.ps1
115 lines (96 loc) · 3.19 KB
/
OfficeC2RCom.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
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
114
115
$OfficeCOM = @"
using System;
using System.Runtime.InteropServices;
namespace OfficeC2RCom
{
[ComImport]
[Guid("90E166F0-D621-4793-BE78-F58008DDDD2A")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IUpdateNotify2
{
[return: MarshalAs(UnmanagedType.U4)]
uint Download([MarshalAs(UnmanagedType.LPWStr)] string pcwszParameters);
[return: MarshalAs(UnmanagedType.U4)]
uint Apply([MarshalAs(UnmanagedType.LPWStr)] string pcwszParameters);
[return: MarshalAs(UnmanagedType.U4)]
uint Cancel();
[return: MarshalAs(UnmanagedType.U4)]
uint status(out UPDATE_STATUS_REPORT pUpdateStatusReport);
[return: MarshalAs(UnmanagedType.U4)]
uint GetBlockingApps(out string AppsList);
[return: MarshalAs(UnmanagedType.U4)]
uint GetOfficeDeploymentData(int dataType, string pcwszName, out string OfficeData);
}
[ComImport]
[Guid("52C2F9C2-F1AC-4021-BF50-756A5FA8DDFE")]
internal class UpdateNotifyObject2 { }
[StructLayout(LayoutKind.Sequential)]
internal struct UPDATE_STATUS_REPORT
{
public UPDATE_STATUS status;
public uint error;
[MarshalAs(UnmanagedType.BStr)] public string contentid;
}
internal enum UPDATE_STATUS
{
eUPDATE_UNKNOWN = 0,
eDOWNLOAD_PENDING,
eDOWNLOAD_WIP,
eDOWNLOAD_CANCELLING,
eDOWNLOAD_CANCELLED,
eDOWNLOAD_FAILED,
eDOWNLOAD_SUCCEEDED,
eAPPLY_PENDING,
eAPPLY_WIP,
eAPPLY_SUCCEEDED,
eAPPLY_FAILED
}
internal enum UPDATE_ERROR_CODE
{
eOK = 0,
eFAILED_UNEXPECTED,
eTRIGGER_DISABLED,
ePIPELINE_IN_USE,
eFAILED_STOP_C2RSERVICE,
eFAILED_GET_CLIENTUPDATEFOLDER,
eFAILED_LOCK_PACKAGE_TO_UPDATE,
eFAILED_CREATE_STREAM_SESSION,
eFAILED_PUBLISH_WORKING_CONFIGURATION,
eFAILED_DOWNLOAD_UPGRADE_PACKAGE,
eFAILED_APPLY_UPGRADE_PACKAGE,
eFAILED_INITIALIZE_RSOD,
eFAILED_PUBLISH_RSOD,
// Keep this one as the last
eUNKNOWN
}
public static class COMObject
{
static IUpdateNotify2 updater;
static UPDATE_STATUS_REPORT report;
public static uint Download(string parameters = "")
{
updater = (IUpdateNotify2)new UpdateNotifyObject2();
return updater.Download(parameters);
}
public static uint Apply(string parameters = "")
{
updater = (IUpdateNotify2)new UpdateNotifyObject2();
return updater.Apply(parameters);
}
public static string GetCOMObjectStatus()
{
updater = (IUpdateNotify2)new UpdateNotifyObject2();
updater.status(out report);
return "{ \"status\":\"" + report.status + "\", \"result\":\"" + report.error + "\"}";
}
public static string[] GetBlockingApps()
{
string blockingApps;
updater = (IUpdateNotify2)new UpdateNotifyObject2();
updater.GetBlockingApps(out blockingApps);
return blockingApps.Split(',');
}
}
}
"@
Add-Type -TypeDefinition $OfficeCOM -Language CSharp