Hack Forums
[C#] Dropping Then Deleting File - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] Dropping Then Deleting File (/showthread.php?tid=5201768)



Dropping Then Deleting File - Holocaust - Mar 13, 2016

Hello i've asked for help before but now i need help on how to drop a dll file that it gets from a web server or smth in a temp folder and after the program closes they get deleted!

Thanks in advance

// Holocaust 🤝


* - Odus - Mar 13, 2016

Perform your cleanup in an OnClosing/ProcessExit event. Only problem is this won't fire if the process is killed or suspended manually.


* - Holocaust - Mar 13, 2016

(Mar 13, 2016 04:35 AM)Odus Wrote:  Perform your cleanup in an OnClosing/ProcessExit event. Only problem is this won't fire if the process is killed or suspended manually.

okok but the program is going to close when the dll gets injected!

do you have any idea of how i may drop it in a temp folder?

// Holocaust 🤝


* - Hawk HF - Mar 13, 2016

(Mar 13, 2016 04:35 AM)Odus Wrote:  Perform your cleanup in an OnClosing/ProcessExit event. Only problem is this won't fire if the process is killed or suspended manually.

Yep. So check to see if the file exists when the program is run again.


* - BahNahNah - Mar 13, 2016

(Mar 13, 2016 04:35 AM)Odus Wrote:  Perform your cleanup in an OnClosing/ProcessExit event. Only problem is this won't fire if the process is killed or suspended manually.

WaitForExit would probably be better because it just waits until the process is terminated.


Code
string dumpPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Temp", Guid.NewGuid().ToString("N") + ".exe");
//Drop to dumpPath
Process p = Process.Start(dumpPath);
p.WaitForExit();
File.Delete(dumpPath);



* - Odus - Mar 13, 2016

(Mar 13, 2016 04:50 AM)BahNahNah Wrote:  WaitForExit would probably be better because it just waits until the process is terminated.

If the child process is terminated then yes, but wasn't OP wanting to delete when the parent process ends?


* - Holocaust - Mar 13, 2016

(Mar 13, 2016 06:35 AM)Odus Wrote:  If the child process is terminated then yes, but wasn't OP wanting to delete when the parent process ends?

i want it to put my dll file in a temp folder and inject it and after injection it will close and the dll will get deleted 😖


* - DudeyDance - Mar 13, 2016

If a process has loaded a .dll with LoadLibrary you won't be able to remove that .dll from the file system because it is in use, if that's what you're asking.
You can delete the injector, sure, but you won't be able to remove the dll.