By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,330 Members | 1,268 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,330 IT Pros & Developers. It's quick & easy.

Delete of file in use

P: n/a
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
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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]
- ni**************@exisconsulting.com

"Aryeh Katz" <ar********@vasco.com> wrote in message
news:MP************************@news.microsoft.com ...
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

Nov 13 '05 #2

P: n/a
Or you could mimic MoveFileEx in this situation by writing the proper value
to this reg key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contro l\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 [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:eU****************@TK2MSFTNGP11.phx.gbl...
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]
- ni**************@exisconsulting.com

"Aryeh Katz" <ar********@vasco.com> wrote in message
news:MP************************@news.microsoft.com ...
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


Nov 13 '05 #3

P: n/a
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]
- ni**************@exisconsulting.com

"Chris Becker" <sl*****@hotmail.com> wrote in message
news:Oi**************@TK2MSFTNGP11.phx.gbl...
Or you could mimic MoveFileEx in this situation by writing the proper value to this reg key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contro l\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 [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote in message news:eU****************@TK2MSFTNGP11.phx.gbl...
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]
- ni**************@exisconsulting.com

"Aryeh Katz" <ar********@vasco.com> wrote in message
news:MP************************@news.microsoft.com ...
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



Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.