Delete of file in use

  • Thread starter Thread starter Aryeh Katz
  • Start date Start date
A

Aryeh Katz

I'm trying to write an uninstaller in c#.
Everything works fine, except for the uninstall executable itself.
In c++, one could delete such a file through
MoveFileEx and MOVEFILE_DELAY_UNTIL_REBOOT.
Is there a similar way of doing this in c#?
Thanks.
Aryeh
 
Aryeh,

There is not a manged way of doing this, but you can easily call the
MoveFileEx function through the P/Invoke layer.

Hope this helps.
 
Or you could mimic MoveFileEx in this situation by writing the proper value
to this reg key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session
Manager\PendingFileRenameOperations

Since it is a reg-multi-sz value, you'll need to write to null chars to the
end:

FilePathToDelete\0\0


Nicholas Paldino said:
Aryeh,

There is not a manged way of doing this, but you can easily call the
MoveFileEx function through the P/Invoke layer.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Aryeh Katz said:
I'm trying to write an uninstaller in c#.
Everything works fine, except for the uninstall executable itself.
In c++, one could delete such a file through
MoveFileEx and MOVEFILE_DELAY_UNTIL_REBOOT.
Is there a similar way of doing this in c#?
Thanks.
Aryeh
 
This is probably not a good idea. The storage mechanism that is used to
enable this activity is only guaranteed through the API call. It is not
guaranteed to always be stored in that registry location.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Chris Becker said:
Or you could mimic MoveFileEx in this situation by writing the proper value
to this reg key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session
Manager\PendingFileRenameOperations

Since it is a reg-multi-sz value, you'll need to write to null chars to the
end:

FilePathToDelete\0\0


in message news:eUKpPf%[email protected]...
Aryeh,

There is not a manged way of doing this, but you can easily call the
MoveFileEx function through the P/Invoke layer.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Aryeh Katz said:
I'm trying to write an uninstaller in c#.
Everything works fine, except for the uninstall executable itself.
In c++, one could delete such a file through
MoveFileEx and MOVEFILE_DELAY_UNTIL_REBOOT.
Is there a similar way of doing this in c#?
Thanks.
Aryeh
 
Back
Top