Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi, I have the FBI ransomeware virus in one of my computers so I want to take this opportunity to experiment and try to get rid of it in my own way. So far, I have done some research stating that the virus creates a .exe file that runs the virus in startup. So I want to create a "vaccine" with my USB. I plan on creating a program that will automatically delete all files from the windows startup directory. So that I can restart the computer and hopefully the popup doesn't appear so I can then download a proper anti-virus and get rid of it all.

Question: So my question is, how can I delete all the files from the windows startup? I have this code but it doesn't seem to work. I know that there are many ways of deleting a directory but this method finds the specific file appropriately.

C#
string path = Environment.GetFolderPath(Environment.SpecialFolder.Startup);

            foreach(string files in Directory.GetFiles(path))
            {
                File.Delete(files);
            }



All help is appreciated.
Posted
Comments
Zoltán Zörgő 11-Sep-12 13:41pm    
This will probably not work. It is not wise to try to remove infected files this way. When this code will run, the malware will be active, and probably locking the files you want to delete. And even if, it is unlikely to be enough...
Sergey Alexandrovich Kryukov 11-Sep-12 13:51pm    
That's right. For this very case (the problem of deleting files) I provided basic information -- please see my answer.
Of course, if cannot help to really fight viruses... :-)
--SA
Sergey Alexandrovich Kryukov 11-Sep-12 13:42pm    
What exactly happens when you try it? Exception? Then provide comprehensive exception information. Or this loop found no files?
Just a note: you probably understand that this is a pretty naive way of fighting viruses. Practically, this activity is pretty much useless.
--SA

1 solution

Please see the comments to the question by Zoltán Zörgő and mine. You did not provide relevant information on what happens. One of the most apparent thing which might happen is this: some executable files in this directory are loaded for execution and are actually executed when you try to execute your code. Also, some data files could be opened by some processes for exclusive access (which is done by default) and not closed. In both cases, it is not possible to delete such files; you would need to kill the processes which hold them.

You can you investigate which process holds which file. For this, I recommend using one utility from the Sysinternals Suite. This set of utilities (formerly from Winternals company, presently at Microsoft) is a must-have for any developer, please see:
http://technet.microsoft.com/en-us/sysinternals/bb842062[^],
http://technet.microsoft.com/en-us/sysinternals/bb545027[^].

The utility you need is "handle.exe", please see:
http://technet.microsoft.com/en-us/sysinternals/bb896655[^].

This utility will scan all kinds of handles, not just file handles. For file, it will scan all file handles matching the file name (so it does not have to be a full path name) and return information sufficient to identify each process, including its pid. So, if you need more information on a process in question, you can also use other Sysinternals utilities, in particular, its Process Explorer:
http://technet.microsoft.com/en-us/sysinternals/bb896653[^].

Note that these considerations are very basic. They along cannot help you to fight really sly viruses, most of which are way more cryptic and hard to remove.

Good luck,
—SA
 
Share this answer
 
v3
Comments
MR. AngelMendez 11-Sep-12 23:13pm    
thanks I'll do some looking but can you show me how to delete the windows startup files anyways just to try, thanks :)
Sergey Alexandrovich Kryukov 12-Sep-12 13:14pm    
First, this is not that easy, not guaranteed, and won't server as an ultimate weapon against viruses.

Let's see: first, experiment manually if the reason is the one I described. Using "handle.exe", for that matter. This way, you can find what holds the files in question from deletion. Than, you can kill the processes using System.Diagnostics.Process.Kill, Sysinternals PsKill.exe or ProcExp.exe(Process Kill and Process Explorer, please see, they are good to have) or just Windows Task Manager, for now. Then you should be able to delete the files. It is works, you can do it all programmatically. It's pretty difficult to develop the code like in those Sysinternals utilities, but alternatively you can just execute them using System.Diagnostics.Process.Start.

However, remember that the system could be already infected. Besides, the files may eventually re-appear, because some other virus process could be executing (the one not located in this directory and not holding any files in this directory). And finally, you should understand that a process can be hidden, so neither Windows Task Manager nor Sysinternals Process Explorer will see it.

Is it sufficient information to delete (or try to delete) those files now?
--SA
MR. AngelMendez 13-Sep-12 12:45pm    
I see, I am going to have to reboot the computer. Besides, the only thing I could do is get the command prompt which is useless because of what you said about hidden processes and there is no way to tell which process is a system process and which is actually the virus process anyways. How can one defeat a virus that blocks all view from the desktop and renders things like taskmanager useless? thanks again
Sergey Alexandrovich Kryukov 13-Sep-12 12:57pm    
You are right. You can only tell which process holds what files.
Sorry, I cannot answer your question about the techniques of hiding the processes form Task Manager and other similar tools. The last time I heard about it was my visit to the Barns & Nobel bookstore, where I looked through a book on hacking and malicious software on Windows. There was a big chapter on hiding the processes. That a lot about deep, unreliable and convoluted system internals, a lot of specific and ad-hoc knowledge, something I'm not going in for.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900