-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 ?
satrter
  • 41
  • 5
  • How does it know where the icon is located? – SomethingDark Apr 04 '15 at 21:12
  • yes that is actually my question , – satrter Apr 04 '15 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 Apr 04 '15 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 Apr 04 '15 at 21:29
  • can't you use C++? It is pretty much easier. – MCHAppy Apr 04 '15 at 23:11
  • i would like to use it but as i said the project should be programmed with C – satrter Apr 04 '15 at 23:13
  • @satrter My point in (1) wasn't that it's bad to write this project in C, but rather that calling out to a batch script from C code is bad form. Are you required to do this part in Batch script? My point in (2) is that the Windows Start Menu doesn't browse through the "Program Files" directory to find programs -- it has a directory full of shortcuts that it displays. And for many of those programs, the icon is specified in the shortcut file. For others, the shortcut is either embedded in the program, or in a directory nearby. There's no solid rule. – brenns10 Apr 05 '15 at 02:29
  • ok , so do you mean that there's no way to solve this problem ? – satrter Apr 05 '15 at 10:51

1 Answers1

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.

Community
  • 1
  • 1
brenns10
  • 3,109
  • 3
  • 22
  • 24