Deleting this

  • Thread starter Thread starter buttslapper
  • Start date Start date
B

buttslapper

Hi,

I'm writing an unistall program (unistall.exe).
When I install my application, I also install unistall.exe.
When I execute unistall.exe, I want to be able to delete the current
folder and contained files.
My problem is that unistall.exe is in use, and therefore, I can not
delete the folder.

Any ideas how can I achieve this ?
 
If you do achieve this, be sure and publish your results. AFAIK, no software
has ever been able to do this.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

What You Seek Is What You Get.
 
Unfortunately I cannot find the article now but I know in the past to achieve
this you needed to update a batch file in windows that would force the deletion
on reboot.

Hope this helps find more information.

Regards
Chris

Hello Kevin,
 
I found an interesting way to do this.

Using the MoveFileEx kernel API call.

Since moving a program in execution is allowed, first, you do a move
for the executable in a temp directory.

Then, you recall a move on this file and new location, with the
destination null and flags sets to DELAY_UNTIL_REBOOT.

The first call has moved your file, so you can copy a new one in the
orginal directory.
The second call will delete (destination == null) the file, and the
flags says "next time you reboot the pc"

I guess MSI is using this technique.

Here's the C# import

[Flags]
enum MoveFileFlags
{
MOVEFILE_REPLACE_EXISTING = 0x00000001,
MOVEFILE_COPY_ALLOWED = 0x00000002,
MOVEFILE_DELAY_UNTIL_REBOOT = 0x00000004,
MOVEFILE_WRITE_THROUGH = 0x00000008,
MOVEFILE_CREATE_HARDLINK = 0x00000010,
MOVEFILE_FAIL_IF_NOT_TRACKABLE = 0x00000020
}

[DllImport("kernel32.dll", SetLastError=true, CharSet=CharSet.Auto)]
static extern bool MoveFileEx(string lpExistingFileName, string
lpNewFileName, MoveFileFlags dwFlags);
 
Back
Top