# Just how do I delete a documents which is secured by an additional procedure in C#?

I'm seeking a means to delete a documents which is secured by an additional procedure making use of C#. I believe the method has to have the ability to locate which procedure is securing the documents (probably by tracking the takes care of, although I'm not exactly sure just how to do this in C#) after that close that procedure prior to having the ability to finish the documents delete making use of File.Delete().

0
2019-05-07 01:11:29
Source Share

If you intend to do it programatically. I'm not exactly sure ... and also I 'd actually advise versus it. If you're simply repairing things by yourself equipment, SysInternals Process Explorer can aid you

Run it, make use of the Find Handle command (I assume it's either in the locate or take care of food selection), and also look for the name of your documents. Once the take care of (s) is located, you can by force close them.

You can after that delete the documents and more.

Be cautious , doing this might create the program which possesses the takes care of to act oddly, as you've simply drawn the typical carpet of under it, yet it functions well when you are debugging your very own wayward code, or when aesthetic workshop/ home windows traveler is being crap and also not launching documents takes care of despite the fact that you informed them to close the documents ages ago ... sigh : -)

0
2019-05-08 21:37:44
Source

Oh, one large hack I used years earlier, is that Windows will not allow you delete documents, yet it does allow you relocate them.

Quasi - type - of - code :

mv %WINDIR%\System32\mfc42.dll %WINDIR\System32\mfc42.dll.old
Install new mfc42.dll
Tell user to save work and restart applications


When the applications reactivated (note we really did not require to reboot the equipment), they filled the new mfc42.dll, and also all was well. That, paired with PendingFileOperations to delete the old one the next time the entire system reactivated, functioned rather well.

0
2019-05-08 21:14:53
Source

Killing various other procedures is not a healthy and balanced point to do. If your circumstance entails something like uninstallation, you can make use of the MoveFileEx to note the apply for removal upon next reboot.

If it shows up that you actually require to delete a documents in operation by an additional procedure, I would certainly advise re - taking into consideration the real trouble prior to taking into consideration any kind of remedies.

0
2019-05-08 21:12:40
Source

You can utilize this program, Handle, to locate which procedure has the lock on your documents. It's a command - line device, so I presume you make use of the result from that ... I'm not exactly sure concerning locating it programmatically.

If removing the documents can wait, you can define it for removal when your computer system next launches :

1. Start REGEDT32 (W2K) or REGEDIT (WXP) and also browse to :

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager

2. W2K and also WXP

• W2K :
Edit
Data Type : REG_MULTI_SZ
Value Name : PendingFileRenameOperations
OK

• WXP :
Edit
New
Multi - String Value
enter
PendingFileRenameOperations

3. In the Data location, enter "\??\" + filename to be removed. LFNs might be gotten in without being installed in quotes. To delete C:\Long Directory Name\Long File Name.exe, enter the adhering to information :

\??\C:\Long Directory Name\Long File Name.exe


Then press OK.

4. The "location documents name" is a null (absolutely no) string. It is gotten in as adheres to :

• W2K :
Edit
Binary
select Data Format : Hex
click at the end of the hex string
enter 0000 (4 absolutely nos)
OK

• WXP :
Right - click the value
pick "Modify Binary Data"
click at the end of the hex string
enter 0000 (4 absolutely nos)
OK

5. Close REGEDT32/REGEDIT and also reboot to delete the documents.

(Shamelessly swiped from some random forum, for posterity's purpose.)

0
2019-05-08 20:55:27
Source

The regular method is as adheres to. You've claimed you intend to do this in C# so below goes ...

1. If you do not recognize which procedure has actually the documents secured, you'll require to check out each procedure's take care of checklist, and also question each take care of to establish if it recognizes the secured documents. Doing this in C# will likely call for P/Invoke or an intermediary C+npls/ CLI to call the indigenous APIs you'll require.
2. As soon as you've identified which procedure (es) have actually the documents secured, you'll require to securely inject a tiny indigenous DLL right into the procedure (you can additionally inject a taken care of DLL, yet this is messier, as you after that need to start or affix to the.NET runtime).
3. That bootstrap DLL after that shuts the take care of making use of CloseHandle, etc

Essentially : the means to unlock a "secured" documents is to inject a DLL documents right into the annoying procedure's address room and also close it on your own. You can do this making use of indigenous or took care of code. Whatever, you're mosting likely to require a percentage of indigenous code or at the very least P/Invoke right into the very same.