1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
- using System ;
5
- using System . IO ;
6
4
using Microsoft . Win32 ;
7
- using WixToolset . Dtf . WindowsInstaller ;
5
+ using Microsoft . Win32 . Msi ;
8
6
9
7
if ( args . Length < 3 )
10
8
{
@@ -99,7 +97,8 @@ static bool DetectSdk(string featureBandVersion, string platform)
99
97
100
98
static bool RemoveDependent ( string dependent )
101
99
{
102
- Installer . SetInternalUI ( InstallUIOptions . Silent ) ;
100
+ // Disable MSI UI
101
+ _ = MsiSetInternalUI ( ( uint ) InstallUILevel . NoChange , IntPtr . Zero ) ;
103
102
104
103
// Open the installer dependencies registry key
105
104
// This has to be an exhaustive search as we're not looking for a specific provider key, but for a specific dependent
@@ -108,7 +107,7 @@ static bool RemoveDependent(string dependent)
108
107
if ( hkInstallerDependenciesKey == null )
109
108
{
110
109
Console . WriteLine ( "Installer dependencies key does not exist." ) ;
111
- return false ; // No dependencies to remove
110
+ return false ;
112
111
}
113
112
114
113
// Iterate over each provider key in the dependencies
@@ -124,10 +123,8 @@ static bool RemoveDependent(string dependent)
124
123
if ( hkDependentsKey == null ) continue ;
125
124
126
125
// Check if the dependent exists and continue if it does not
127
- string [ ] dependentsKeys = hkDependentsKey . GetSubKeyNames ( ) ;
128
126
bool dependentExists = false ;
129
-
130
- foreach ( string dependentsKeyName in dependentsKeys )
127
+ foreach ( string dependentsKeyName in hkDependentsKey . GetSubKeyNames ( ) )
131
128
{
132
129
if ( string . Equals ( dependentsKeyName , dependent , StringComparison . OrdinalIgnoreCase ) )
133
130
{
@@ -138,7 +135,7 @@ static bool RemoveDependent(string dependent)
138
135
139
136
if ( ! dependentExists )
140
137
{
141
- continue ; // Skip to the next provider key if the dependent does not exist
138
+ continue ;
142
139
}
143
140
144
141
Console . WriteLine ( $ "Dependent match found: { dependent } ") ;
@@ -163,8 +160,8 @@ static bool RemoveDependent(string dependent)
163
160
{
164
161
string productCode = hkProviderKey . GetValue ( "ProductId" ) . ToString ( ) ;
165
162
166
- // Configure the product to be absent
167
- Installer . ConfigureProduct ( productCode , 0 , InstallState . Absent , "" ) ;
163
+ // Configure the product to be absent (uninstall the product)
164
+ uint error = MsiConfigureProductEx ( productCode , ( int ) InstallUILevel . Default , InstallState . ABSENT , "" ) ;
168
165
Console . WriteLine ( "Product configured to absent successfully." ) ;
169
166
}
170
167
catch ( Exception ex )
@@ -244,3 +241,11 @@ static bool IsRebootPending()
244
241
Console . WriteLine ( "No reboot pending." ) ;
245
242
return false ;
246
243
}
244
+
245
+ [ DllImport ( "msi.dll" , CharSet = CharSet . Unicode ) ]
246
+ [ DefaultDllImportSearchPaths ( DllImportSearchPath . System32 ) ]
247
+ static extern uint MsiConfigureProductEx ( string szProduct , int iInstallLevel , InstallState eInstallState , string szCommandLine ) ;
248
+
249
+ [ DllImport ( "msi.dll" , CharSet = CharSet . Unicode ) ]
250
+ [ DefaultDllImportSearchPaths ( DllImportSearchPath . System32 ) ]
251
+ static extern uint MsiSetInternalUI ( uint dwUILevel , IntPtr phWnd ) ;
0 commit comments