Skip to content

Commit 3f63113

Browse files
GZidarflcdrg
authored andcommitted
Conditions and uninstall scripts working
1 parent 8ef2b7d commit 3f63113

7 files changed

Lines changed: 226 additions & 37 deletions

File tree

PowerShellActions/CustomAction.cs

Lines changed: 93 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,39 @@ public class CustomActions
1717
// Specify or calculate the total number of ticks the custom action adds to the length of the ProgressBar
1818
public const uint TotalTicks = TickIncrement * NumberItems;
1919
private const uint NumberItems = 100;
20+
2021
private const string PowerShellFilesElevatedDeferredProperty = "PowerShellFilesElevatedDeferred";
2122
private const string PowerShellFilesDeferredProperty = "PowerShellFilesDeferred";
2223
private const string PowerShellScriptsElevatedDeferredProperty = "PowerShellScriptsElevatedDeferred";
2324
private const string PowerShellScriptsDeferredProperty = "PowerShellScriptsDeferred";
2425

26+
private const string PowerShellFilesElevatedUninstallDeferredProperty = "PowerShellFilesElevatedUninstallDeferred";
27+
private const string PowerShellFilesUninstallDeferredProperty = "PowerShellFilesUninstallDeferred";
28+
private const string PowerShellScriptsElevatedUninstallDeferredProperty = "PowerShellScriptsElevatedUninstallDeferred";
29+
private const string PowerShellScriptsUninstallDeferredProperty = "PowerShellScriptsUninstallDeferred";
30+
2531
[CustomAction]
2632
public static ActionResult PowerShellFilesImmediate(Session session)
2733
{
34+
session.Log("PowerShellFilesImmediate start");
35+
2836
return FilesImmediate(session, 0, PowerShellFilesDeferredProperty);
2937
}
3038

3139
[CustomAction]
32-
public static ActionResult PowerShellFilesElevatedImmediate(Session session)
40+
public static ActionResult PowerShellFilesDeferred(Session session)
3341
{
34-
return FilesImmediate(session, 1, PowerShellFilesElevatedDeferredProperty);
42+
session.Log("PowerShellFilesDeferred start");
43+
44+
return FilesDeferred(session, PowerShellFilesDeferredProperty);
3545
}
3646

3747
[CustomAction]
38-
public static ActionResult PowerShellFilesDeferred(Session session)
48+
public static ActionResult PowerShellFilesElevatedImmediate(Session session)
3949
{
40-
session.Log("PowerShellFilesDeferred start");
50+
session.Log("PowerShellFilesElevatedImmediate start");
4151

42-
return FilesDeferred(session, PowerShellFilesDeferredProperty);
52+
return FilesImmediate(session, 1, PowerShellFilesElevatedDeferredProperty);
4353
}
4454

4555
[CustomAction]
@@ -51,29 +61,103 @@ public static ActionResult PowerShellFilesElevatedDeferred(Session session)
5161
}
5262

5363
[CustomAction]
54-
public static ActionResult PowerShellScriptsImmediate(Session session)
64+
public static ActionResult PowerShellFilesUninstall(Session session)
5565
{
56-
return ScriptsImmediate(session, 0, PowerShellScriptsDeferredProperty);
66+
session.Log("PowerShellFilesUninstall start");
67+
68+
return FilesImmediate(session, 0, PowerShellFilesUninstallDeferredProperty);
5769
}
5870

71+
5972
[CustomAction]
60-
public static ActionResult PowerShellScriptsElevatedImmediate(Session session)
73+
public static ActionResult PowerShellFilesUninstallDeferred(Session session)
6174
{
62-
return ScriptsImmediate(session, 1, PowerShellScriptsElevatedDeferredProperty);
75+
session.Log("PowerShellFilesUninstallDeferred start");
76+
77+
return FilesDeferred(session, PowerShellFilesUninstallDeferredProperty);
78+
}
79+
80+
81+
[CustomAction]
82+
public static ActionResult PowerShellFilesElevatedUninstall(Session session)
83+
{
84+
session.Log("PowerShellFilesElevatedUninstall start");
85+
86+
return FilesImmediate(session, 1, PowerShellFilesElevatedUninstallDeferredProperty);
87+
}
88+
89+
[CustomAction]
90+
public static ActionResult PowerShellFilesElevatedUninstallDeferred(Session session)
91+
{
92+
session.Log("PowerShellFilesElevatedUninstallDeferred start");
93+
94+
return FilesDeferred(session, PowerShellFilesElevatedUninstallDeferredProperty);
95+
}
96+
97+
[CustomAction]
98+
public static ActionResult PowerShellScriptsImmediate(Session session)
99+
{
100+
session.Log("PowerShellScriptsImmediate start");
101+
102+
return ScriptsImmediate(session, 0, PowerShellScriptsDeferredProperty);
63103
}
64104

65105
[CustomAction]
66106
public static ActionResult PowerShellScriptsDeferred(Session session)
67107
{
108+
session.Log("PowerShellScriptsDeferred start");
109+
68110
return ScriptsDeferred(session, PowerShellScriptsDeferredProperty);
69111
}
70112

113+
[CustomAction]
114+
public static ActionResult PowerShellScriptsElevatedImmediate(Session session)
115+
{
116+
session.Log("PowerShellScriptsElevatedImmediate start");
117+
118+
return ScriptsImmediate(session, 1, PowerShellScriptsElevatedDeferredProperty);
119+
}
120+
71121
[CustomAction]
72122
public static ActionResult PowerShellScriptsElevatedDeferred(Session session)
73123
{
124+
session.Log("PowerShellScriptsElevatedDeferred start");
125+
74126
return ScriptsDeferred(session, PowerShellScriptsElevatedDeferredProperty);
75127
}
76128

129+
[CustomAction]
130+
public static ActionResult PowerShellScriptsUninstall(Session session)
131+
{
132+
session.Log("PowerShellScriptsUninstall start");
133+
134+
return ScriptsImmediate(session, 0, PowerShellScriptsUninstallDeferredProperty);
135+
}
136+
137+
[CustomAction]
138+
public static ActionResult PowerShellScriptsUninstallDeferred(Session session)
139+
{
140+
session.Log("PowerShellScriptsUninstallDeferred start");
141+
142+
return ScriptsDeferred(session, PowerShellScriptsUninstallDeferredProperty);
143+
}
144+
145+
[CustomAction]
146+
public static ActionResult PowerShellScriptsElevatedUninstall(Session session)
147+
{
148+
session.Log("PowerShellScriptsElevatedUninstall start");
149+
150+
return ScriptsImmediate(session, 1, PowerShellScriptsElevatedUninstallDeferredProperty);
151+
}
152+
153+
[CustomAction]
154+
public static ActionResult PowerShellScriptsElevatedUninstallDeferred(Session session)
155+
{
156+
session.Log("PowerShellScriptsElevatedUninstallDeferred start");
157+
158+
return ScriptsDeferred(session, PowerShellScriptsElevatedUninstallDeferredProperty);
159+
}
160+
77161
[Serializable]
78162
public class ScriptActionData
79163
{

PowerShellActions/PowerShellActions.csproj

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,22 @@
1414
<FileAlignment>512</FileAlignment>
1515
<WixCATargetsPath Condition=" '$(WixCATargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.CA.targets</WixCATargetsPath>
1616
</PropertyGroup>
17-
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
1818
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
1921
<OutputPath>bin\Debug\</OutputPath>
2022
<DefineConstants>DEBUG;TRACE</DefineConstants>
21-
<DebugType>full</DebugType>
22-
<PlatformTarget>x86</PlatformTarget>
2323
<ErrorReport>prompt</ErrorReport>
24-
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
24+
<WarningLevel>4</WarningLevel>
2525
</PropertyGroup>
26-
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
2729
<OutputPath>bin\Release\</OutputPath>
2830
<DefineConstants>TRACE</DefineConstants>
29-
<Optimize>true</Optimize>
30-
<DebugType>pdbonly</DebugType>
31-
<PlatformTarget>x86</PlatformTarget>
3231
<ErrorReport>prompt</ErrorReport>
33-
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
32+
<WarningLevel>4</WarningLevel>
3433
</PropertyGroup>
3534
<ItemGroup>
3635
<Reference Include="System" />

PowerShellLibrary/Library.wxs

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@
1515
Impersonate="yes"
1616
Execute="deferred"
1717
Return="check" />
18+
19+
<CustomAction Id="PowerShellScriptsUninstall"
20+
BinaryKey="CA_DLL"
21+
DllEntry="PowerShellScriptsUninstall"
22+
Execute="immediate"
23+
Return="check" />
24+
25+
<CustomAction Id="PowerShellScriptsUninstallDeferred"
26+
BinaryKey="CA_DLL"
27+
DllEntry="PowerShellScriptsUninstallDeferred"
28+
Impersonate="yes"
29+
Execute="deferred"
30+
Return="check" />
1831

1932
<CustomAction Id="PowerShellScriptsElevatedImmediate"
2033
BinaryKey="CA_DLL"
@@ -29,6 +42,19 @@
2942
Execute="deferred"
3043
Return="check" />
3144

45+
<CustomAction Id="PowerShellScriptsElevatedUninstall"
46+
BinaryKey="CA_DLL"
47+
DllEntry="PowerShellScriptsElevatedUninstall"
48+
Execute="immediate"
49+
Return="check" />
50+
51+
<CustomAction Id="PowerShellScriptsElevatedUninstallDeferred"
52+
BinaryKey="CA_DLL"
53+
DllEntry="PowerShellScriptsElevatedUninstallDeferred"
54+
Impersonate="no"
55+
Execute="deferred"
56+
Return="check" />
57+
3258
<CustomAction Id="PowerShellFilesImmediate"
3359
BinaryKey="CA_DLL"
3460
DllEntry="PowerShellFilesImmediate"
@@ -42,6 +68,19 @@
4268
Execute="deferred"
4369
Return="check" />
4470

71+
<CustomAction Id="PowerShellFilesUninstall"
72+
BinaryKey="CA_DLL"
73+
DllEntry="PowerShellFilesUninstall"
74+
Execute="immediate"
75+
Return="check" />
76+
77+
<CustomAction Id="PowerShellFilesUninstallDeferred"
78+
BinaryKey="CA_DLL"
79+
DllEntry="PowerShellFilesUninstallDeferred"
80+
Impersonate="yes"
81+
Execute="deferred"
82+
Return="check" />
83+
4584
<CustomAction Id="PowerShellFilesElevatedImmediate"
4685
BinaryKey="CA_DLL"
4786
DllEntry="PowerShellFilesElevatedImmediate"
@@ -55,7 +94,20 @@
5594
Execute="deferred"
5695
Return="check" />
5796

58-
<InstallExecuteSequence>
97+
<CustomAction Id="PowerShellFilesElevatedUninstall"
98+
BinaryKey="CA_DLL"
99+
DllEntry="PowerShellFilesElevatedUninstall"
100+
Execute="immediate"
101+
Return="check" />
102+
103+
<CustomAction Id="PowerShellFilesElevatedUninstallDeferred"
104+
BinaryKey="CA_DLL"
105+
DllEntry="PowerShellFilesElevatedUninstallDeferred"
106+
Impersonate="no"
107+
Execute="deferred"
108+
Return="check" />
109+
110+
<InstallExecuteSequence>
59111
<!-- These are the 'immediate' actions that prep the data for the 'deferred' actions-->
60112
<Custom Action="PowerShellScriptsImmediate" Before="PowerShellScriptsDeferred" Overridable="yes">NOT Installed</Custom>
61113

@@ -74,13 +126,35 @@
74126

75127
<Custom Action="PowerShellFilesElevatedDeferred" After="InstallFiles" Overridable="yes">NOT Installed</Custom>
76128

77-
</InstallExecuteSequence>
129+
<!-- 'Uninstall immediate' actions -->
130+
<Custom Action="PowerShellScriptsUninstall" Before="PowerShellScriptsUninstallDeferred" Overridable="yes">REMOVE="ALL"</Custom>
131+
132+
<Custom Action="PowerShellScriptsElevatedUninstall" Before="PowerShellScriptsElevatedUninstallDeferred" Overridable="yes">REMOVE="ALL"</Custom>
133+
134+
<Custom Action="PowerShellFilesUninstall" Before="PowerShellFilesUninstallDeferred" Overridable="yes">REMOVE="ALL"</Custom>
135+
136+
<Custom Action="PowerShellFilesElevatedUninstall" Before="PowerShellFilesElevatedUninstallDeferred" Overridable="yes">REMOVE="ALL"</Custom>
137+
138+
<!-- 'Uninstall deferred' actions -->
139+
<Custom Action="PowerShellScriptsUninstallDeferred" After="RemoveFiles" Overridable="yes">REMOVE="ALL"</Custom>
140+
141+
<Custom Action="PowerShellScriptsElevatedUninstallDeferred" After="RemoveFiles" Overridable="yes">REMOVE="ALL"</Custom>
142+
143+
<Custom Action="PowerShellFilesUninstallDeferred" After="RemoveFiles" Overridable="yes">REMOVE="ALL"</Custom>
144+
145+
<Custom Action="PowerShellFilesElevatedUninstallDeferred" After="RemoveFiles" Overridable="yes">REMOVE="ALL"</Custom>
146+
</InstallExecuteSequence>
78147

79148
<UI>
80149
<ProgressText Action="PowerShellFilesDeferred">PowerShell Files</ProgressText>
81150
<ProgressText Action="PowerShellScriptsDeferred">PowerShell Inline</ProgressText>
82151
<ProgressText Action="PowerShellScriptsElevatedDeferred">PowerShell Inline (elevated)</ProgressText>
83152
<ProgressText Action="PowerShellFilesElevatedDeferred">PowerShell Files (elevated)</ProgressText>
84-
</UI>
153+
154+
<ProgressText Action="PowerShellFilesUninstallDeferred">PowerShell Uninstall Files</ProgressText>
155+
<ProgressText Action="PowerShellScriptsUninstallDeferred">PowerShell Uninstall Inline</ProgressText>
156+
<ProgressText Action="PowerShellScriptsElevatedUninstallDeferred">PowerShell Uninstall Inline (elevated)</ProgressText>
157+
<ProgressText Action="PowerShellFilesElevatedUninstallDeferred">PowerShell Uninstall Files (elevated)</ProgressText>
158+
</UI>
85159
</Fragment>
86160
</Wix>

PowerShellWixExtension.nuspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
33
<metadata minClientVersion="2.7">
44
<id>PowerShellWixExtension</id>
5-
<version>2.1.0</version>
5+
<version>4.0.0</version>
66
<title>Wix Extension for PowerShell</title>
77
<summary>Wix Extension that allows running PowerShell scripts</summary>
88
<description>An extension for Wix that allows running PowerShell scripts, either from .ps1 files included in the MSI, or by embedding PowerShell script directly</description>
@@ -14,6 +14,7 @@
1414
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1515
<tags>WiX PowerShell MSI Installer WixToolset XML</tags>
1616
<releaseNotes>$releasenotes$</releaseNotes>
17+
* Support for running scripts on uninstall (from @gzidar)
1718
</metadata>
1819
<files>
1920
<file src="NuGet\content\*.*" target="content" />

0 commit comments

Comments
 (0)