Hi everyone. Basically what I want to do is search for a specific *.exe file upon initialization of my application. The *.exe file that I want to search for happens to be a .NET debugging tool. When / if my application finds this file, I want it to automatically close and delete itself. The problem is, not everybody will have that *.exe file installed in the same place. Is there a way I can search the entire HD instead of specific folders to find the file? Would @"C:\" search the desktop, My Documents, etc? I'm also not really sure how I can make my program delete itself upon detection; maybe I should start a new thread for that after I figure this out.

Thanks in advance :P

This piece of code enumerate on the local drives then gets it root path then search for every exe on you can use SystemFileInfo to handle nested directories...

foreach (System.IO.DriveInfo dirveInfo in System.IO.DriveInfo.GetDrives())
            {
                foreach(System.IO.FileInfo fileInfo in dirveInfo.RootDirectory.GetFiles("*.exe"))
                    ///add the exe in list or handle it as you like
            }

Edited 7 Years Ago by Ramy Mahrous: n/a

What are you trying to accomplish here? I only can only think of one type of software that behaves like this.............

Please elaborate

Basically I'm adding a few levels of protection scheme. I'm searching all drives for programs like .NET Reflector and some various .NET deobfuscation / debugging tools. When/if these are found my program will delete itself. I have all of this ontop of a custom serial algorithm based on Genetics and Sudoku(LOL). Of course, if this were commercial software I would never go through that much trouble, but it's for a class I'm in to help demonstrate security vulnerabilities.

I still don't understand, but to search an entire drive for a file is not difficult to do:

DirectoryInfo di = new DirectoryInfo(@"c:\");
            FileInfo[] finfos = di.GetFiles("*.exe", SearchOption.AllDirectories);
            foreach (FileInfo fi in finfos)
                ; // do something with the file info

Something I begun to note is most of askers ignore my reply... and even don't comment, what does it mean????!!!
@papanyquiL didn't you see my reply?? or I should clarify?? or you aren't satisfied with the code??

Edited 7 Years Ago by Ramy Mahrous: n/a

Something I begun to note is most of askers ignore my reply... and even don't comment, what does it mean????!!!
@papanyquiL didn't you see my reply?? or I should clarify?? or you aren't satisfied with the code??

Yes Ramy I saw your reply and it worked fine. I just forgot to mark this thread as solved because I was answering some other questions. Thanks for the help everyone :)

This question has already been answered. Start a new discussion instead.