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