@@ -178,41 +178,51 @@ BOOLEAN SetupCreateUninstallFile(
178
178
179
179
// Check if the user has started the setup from the installation folder.
180
180
if (PhStartsWithStringRef2 (& currentFilePath , PhGetString (Context -> SetupInstallPath ), TRUE))
181
- {
182
- // Do nothing, latest version already in the installation folder.
183
181
return TRUE;
184
- }
185
182
186
183
backupFilePath = PhConcatStrings2 (PhGetString (Context -> SetupInstallPath ), L"\\processhacker-setup.bak" );
187
184
uninstallFilePath = PhConcatStrings2 (PhGetString (Context -> SetupInstallPath ), L"\\processhacker-setup.exe" );
188
185
189
186
if (RtlDoesFileExists_U (backupFilePath -> Buffer ))
190
187
{
191
- // TODO: Move to temp directory
192
- }
188
+ GUID randomGuid ;
189
+ PPH_STRING tempPath = NULL ;
190
+ PPH_STRING guidString = NULL ;
193
191
194
- if (RtlDoesFileExists_U (uninstallFilePath -> Buffer ))
195
- {
196
- if (!DeleteFile (backupFilePath -> Buffer ))
192
+ tempPath = PhCreateStringEx (NULL , GetTempPath (0 , NULL ) * sizeof (WCHAR ));
193
+ GetTempPath ((ULONG )tempPath -> Length / sizeof (WCHAR ), tempPath -> Buffer );
194
+
195
+ PhGenerateGuid (& randomGuid );
196
+
197
+ if (guidString = PhFormatGuid (& randomGuid ))
198
+ {
199
+ PhMoveReference (& guidString , PhSubstring (guidString , 1 , guidString -> Length / sizeof (WCHAR ) - 2 ));
200
+ }
201
+
202
+ PhMoveReference (& guidString , PhConcatStrings (
203
+ 3 ,
204
+ PhGetString (tempPath ),
205
+ L"\\" ,
206
+ PhGetString (guidString )
207
+ ));
208
+
209
+ if (!MoveFile (backupFilePath -> Buffer , guidString -> Buffer ))
197
210
{
198
211
Context -> ErrorCode = GetLastError ();
199
- PhDereferenceObject (uninstallFilePath );
200
- return FALSE;
201
212
}
213
+ }
202
214
215
+ if (RtlDoesFileExists_U (uninstallFilePath -> Buffer ))
216
+ {
203
217
if (!MoveFile (uninstallFilePath -> Buffer , backupFilePath -> Buffer ))
204
218
{
205
219
Context -> ErrorCode = GetLastError ();
206
- PhDereferenceObject (uninstallFilePath );
207
- return FALSE;
208
220
}
209
221
}
210
222
211
- if (!CopyFile (currentFilePath .Buffer , uninstallFilePath -> Buffer , FALSE ))
223
+ if (!CopyFile (currentFilePath .Buffer , uninstallFilePath -> Buffer , TRUE ))
212
224
{
213
225
Context -> ErrorCode = GetLastError ();
214
- PhDereferenceObject (uninstallFilePath );
215
- return FALSE;
216
226
}
217
227
218
228
PhDereferenceObject (uninstallFilePath );
@@ -336,27 +346,24 @@ BOOLEAN SetupUninstallKph(
336
346
_In_ PPH_SETUP_CONTEXT Context
337
347
)
338
348
{
339
- BOOLEAN deleted = FALSE;
340
- SC_HANDLE serviceHandle ;
341
- SERVICE_STATUS serviceStatus ;
342
-
343
- if (serviceHandle = PhOpenService (
344
- L"KProcessHacker3" ,
345
- SERVICE_STOP | DELETE
346
- ))
349
+ while (TRUE)
347
350
{
348
- ControlService (serviceHandle , SERVICE_CONTROL_STOP , & serviceStatus );
351
+ SC_HANDLE serviceHandle ;
352
+ SERVICE_STATUS serviceStatus ;
349
353
350
- deleted = DeleteService (serviceHandle );
354
+ if (!(serviceHandle = PhOpenService (
355
+ L"KProcessHacker3" ,
356
+ SERVICE_STOP | DELETE
357
+ )))
358
+ break ;
359
+
360
+ ControlService (serviceHandle , SERVICE_CONTROL_STOP , & serviceStatus );
361
+ DeleteService (serviceHandle );
351
362
352
363
CloseServiceHandle (serviceHandle );
353
364
}
354
- else
355
- {
356
- deleted = TRUE;
357
- }
358
365
359
- return deleted ;
366
+ return TRUE ;
360
367
}
361
368
362
369
VOID SetupSetWindowsOptions (
0 commit comments