-1

I am working on a small c project , it is a menu that contains all
the programs that the user have . so i need a batch script that

  • takes the the program's name or path
  • returns the full path of it's icon . can you help ?
8
  • How does it know where the icon is located? Commented Apr 4, 2015 at 21:12
  • yes that is actually my question ,
    – satrter
    Commented Apr 4, 2015 at 21:20
  • Two things: (1) having a C program that relies on a script to do such an important part isn't really a good design. (2) I believe that icons are usually specified inside the Windows shortcut.
    – brenns10
    Commented Apr 4, 2015 at 21:20
  • (1) the C part wasn't an option i am a students and we had to do a c project (2) sorry that didn't help
    – satrter
    Commented Apr 4, 2015 at 21:29
  • can't you use C++? It is pretty much easier.
    – MCHAppy
    Commented Apr 4, 2015 at 23:11

1 Answer 1

0

This is not an impossible task (after all, Windows does it!). Typically, a program's icon is specified in one of two places: within the program binary itself, or in the shortcut to the program.

  • Within the program binary: Windows programs (EXEs and DLLs) use a format called Portable Executable (PE) format. This file format specifies the organization of code and data for programs. Icons would be stored somewhere in here. So, you would need to parse the PE format in order to get the icon. Thankfully, it looks like Windows provides a function for getting icons: ExtractIconEx. You might use this to get an icon from a program. Here's an article I found that has some commentary on that function. Some of the links in it are dead--Google is your best friend.

  • In the shortcut: Here is an already answered StackOverflow question about getting icons from shortcuts. Something in there might be helpful.

Some additional comments:

  • Finding every EXE in the Program Files directories will be slow and useless. There are plenty of programs in there that nobody wants to use. What you'll want to do is parse the shortcuts in the Start Menu folder.
  • From there, you'll want to get the icon from the shortcut. If that fails, get it from the program itself.

I hope this helps.

Not the answer you're looking for? Browse other questions tagged or ask your own question.