Delete of file in use

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
C

Chris Becker

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
 
N

Nicholas Paldino [.NET/C# MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top