Click here to Skip to main content
15,901,666 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello fellow users of CodeProject!

So my most recent project has become a "Exe Library" which means that in theory the user will be able to Press a button & it will find all the executables.

Which way would would I take to start this journey.
(My idea is something like this.)
http://imgur.com/WpXIXs4

Would I have to use a specific API? (Read somewhere that it could make easier if I used a WIndows API)

Would "DirectoryInfo" benefit me at all?

What Loops would you use?

I would like to say that im not looking for any code in specific I am simply looking for a someone to tell me what way to go & what kind of information I should & should not look for.
Any answer is highly appreciated.
Thanks!
Posted
Comments
Sergey Alexandrovich Kryukov 15-Dec-15 21:32pm    
Excuse me, what is "WPF Form"?
Why finding all the executables? This functionality is already available.
The questions about API and loops simply makes no sense. Everyone who knows programming can use all this, and those who cannot... this is not a good way to get education by asking questions on forums. This forum can help people who face real difficulties, have real concerns, need some general advice, and so on.
—SA
BladeLogan 15-Dec-15 22:16pm    
I am teribly sorry about how I asked the question, maybe I should of put it like this instead.

When creating my WPF Application* (Not form, I've been up for 28 hours now and things are getting confusing (I will sleep dont worry I'l get to that later today) When Creating a WPF Application that can locate executables by pressing a button for example " http://imgur.com/D6ecP75 "
The issue I am having at the moment is use the code to find all exes recursively in a directory which I can do with "DirectoryInfo" Class and later on

foreach ( var exeFile in exeFiles )
{
Console.WriteLine( exeFile );
}

All of that is not rellevant thats why I didnt want to bring it up in the first place & have this very long conversation about my code. I simply needed guidence from someone who has made something similar to this & could give me some pointers to make it as "efficient" as possible.

I hope im making any sence, English is not my naitive tounge.
Sergey Alexandrovich Kryukov 15-Dec-15 23:15pm    
First of all, no need to apologize; it's just normal working moments. It's don't be afraid of long conversations. It's much more efficient to put all points under 'i' in first place, better than getting confused off-topic answers.

First of all, what do you mean by executables? It can be, for example; 1) all files named as *.exe or *.exe and *.dll, 2) all files with PE signature, 3) something else.

How the example of "http://imgur.com/D6ecP75" can be relevant? Normally, "executable files" is something exposed to your code only on local system.

Why "foreach(var exeFule in exeFiles)" is irrelevant? If you really want to get files by some name pattern, this is what you have to do, but you don't need to write recursive code, it's already done for you in Directory.GetFiles...

So, what's the problem and what guidance you need? I'll gladly try to help as soon as I understand it all.

By the way, your English is good enough for this purpose.

—SA
BladeLogan 15-Dec-15 23:28pm    
Thank you for being patient & I am not really good with explaining myself because I can see it so very clear in my head but when it comes to putting it to words its a bit harder.

Yes, All the *.exe files
at the moment I am working with this code

OpenFileDialog ofd = new OpenFileDialog();
ofd.InitialDirectory = @"c:";
if (ofd.ShowDialog() == true)
ofd.Filter = "*.exe";

Its far away from being complete & it is not even the "purpose" I want to use for this type of Application I want it to display a box with a list of all the (*.exe) files installed on the pc for exaple.
When you get prompted on how to open a new file for example a .vbs file. It always gives you the option to choose from a list & then you get to choose which one you would like to use.
I would love to be avalible to activate that same list type from my software.

Or this is even a better example. (If you have ever used cheat engine.)
http://imgur.com/Uv4isWE

When you press the computer icon at the top left corner of the software (Cheat Engine) it prompts you with that list type (All the exe's installed or running on your machine)

I am trying to recreate something similar with my software, The only thing is I think im headed the wrong direction I am kinda new to that "field" in programming. I spend most of my time making SoundBoards, NotePads with databases etc.

Not everything is clear in your explanation, but I'll start to answer.

The *.exe files is not all the "executable files", but if this is all you need, you can obtain the whole set of the file using the method System.IO.Directory.GetFile, the 3rd method of these three, the one with SearchOption:
https://msdn.microsoft.com/en-us/library/system.io.directory.getfiles%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/ms143316(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/ms143448%28v=vs.110%29.aspx[^].

SearchOption.AllDirectories gives you the all the list of files at once, taken by recursing the directories.

Now, "all the file installed" is completely different thing and "all running on your machine" is another different thing. If you meant that all of the above is irrelevant to both of these problem, you were perfectly right.

Let's start with "all running". No, this is not a correctly posed problem. Files are not running. Running are applications and processes. You can get all processes in the system:
https://msdn.microsoft.com/en-us/library/1f3ys1f9(v=vs.110).aspx[^].

Then you can take each instance of the returned processes, of the type System.Diagnostics.Process, and get all the information of each process: https://msdn.microsoft.com/en-us/library/system.diagnostics.process%28v=vs.110%29.aspx[^].

Now, we are coming to files. No, it's not just the file. You have to understand that each process used one or more executable files, and executable file is not *.exe. It could be *.dll, and a lot more. Real "executable file" is the PE file. You need to understand what it really is: https://en.wikipedia.org/wiki/Portable_Executable[^].

To get all the information, you need to get the properties of each process, Process.Modules and Process.MainModule:
https://msdn.microsoft.com/en-us/library/system.diagnostics.process.mainmodule(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/system.diagnostics.process.modules(v=vs.110).aspx[^].

Then, from module, you can come to executable files:
https://msdn.microsoft.com/en-us/library/system.diagnostics.processmodule%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.diagnostics.processmodule.filename(v=vs.110).aspx[^],
(and see other properties).

I want to stop here for now. It's more than enough for a single answer. Please tell me if you still want to know about "installed applications" (again, not files, but not processes; applications). I want to warn you: this topic is much harder, and at the same time, much less important, less fundamental and more platform-specific. I'm not sure you really need to list it. But if you think you need, let me discuss it in a separate answer. This one is already a bit too much.

—SA
 
Share this answer
 
Comments
BladeLogan 16-Dec-15 0:26am    
Wow! This was more then I was looking for, dont get me wrong I ame xtreamly greatful with what you have supplied for me. I start reading up about this & see how much I can get done before I hit they hay.
Thanks again!
Sergey Alexandrovich Kryukov 16-Dec-15 0:55am    
You are very welcome.
Good luck, call again.
—SA
By the way, about "installed applications" you mentioned. I found this CodeProject article which explains pretty much all the topic: http://www.codeproject.com/Tips/782919/Get-List-of-Installed-Applications-of-System-in-Cs[^].

First thing to understand: this is not the list of installed "files" and not even application. This is the list of installed products. Read the article, and you will understand what information you get with each item.

—SA
 
Share this answer
 
Comments
BladeLogan 16-Dec-15 0:37am    
Thank you for everything! This is as close to as it will get to identifying my issue. I will follow this guide & also read up on the other stuff, it all seemed really interesting, thanks!

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