3

I was wondering if it was possible in Delphi to implement some items added to the right-click menu of an EXE file, specifically a Windows Service Application EXE which has not yet been registered or installed anywhere. The menu options would allow user to install/uninstall the EXE as a windows service. Is this possible? If so, then how? It's OK if it's only compatible with Windows Vista+.

There would be 2 menu items:

  • Install (or Uninstall)
  • Start (or Stop)
Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327
  • individual files do not declare information for the Windows right-click menu to display. are you asking how to do this for one particular executable file? – ardnew Feb 20 '12 at 02:21
  • 3
    Why the downvote? This is a perfectly valid question. – Leonardo Herrera Feb 20 '12 at 14:27
  • @LeonardoHerrera Agreed - A question of whether something is possible with an answer of no doesn't mean it should be downvoted. – Jerry Dodge Feb 20 '12 at 14:59

2 Answers2

5

If you're referring to the Shell Context Menu (the right-click window in Windows Explorer), you cannot. You can add to the menu that will be displayed for all .exe files, but not for an individual one.

You could register a context menu handler for all executables, and then filter the filename passed to see if you needed to handle it or not, but this would mean that for every one of the hundreds (or thousands) of executable files on your machine, your filter would run on the slim chance it was your application that was right-clicked.

A possible workaround would be to put a file with a custom extension in your service's folder, and add a context menu handler for that file instead. When that file is right-clicked, the menu items would simply call your service with the appropriate command-line parameters.

(Of course, the best solution is to use the Control Panel's Services applet to manage your service, which is what it's designed specifically do do.)

Ken White
  • 123,280
  • 14
  • 225
  • 444
3

It is possible, and you need to write shell extensions for Windows Explorer.

References:

http://delphi.about.com/library/bluc/text/uc071701a.htm

http://www.andreanolanusse.com/en/shell-extension-for-windows-32-bit-and-64-bit-with-delphi-xe2/

http://www.codeproject.com/Articles/441/The-Complete-Idiot-s-Guide-to-Writing-Shell-Extens

Lex Li
  • 60,503
  • 9
  • 116
  • 147
  • 1
    No, it's not. You can't add to the context menu for a specific executable. You can add one for *all* executables, but not for an individual one. – Ken White Feb 20 '12 at 02:49
  • I don't think that's impossible, http://www.codeproject.com/Articles/441/The-Complete-Idiot-s-Guide-to-Writing-Shell-Extens From this article it indicates that you can filter by file names. – Lex Li Feb 20 '12 at 03:39
  • 2
    Sure. This means that, for every single executable on your system that is right-clicked, your extension get called, and there's a delay on the system while your filter runs. Doing something that silly is a total waste of system resources and negatively impacts the entire system. There is no *practical* way to add a context menu for a single file. (A more practical solution would be to put a separate file in your service's folder, register a handler for the extension of that separate file, and set up your service as the handler for that new file extension.) – Ken White Feb 20 '12 at 03:45
  • While I totally agree with you, Ken, I just wonder what @JerryDodge prefers :) – Lex Li Feb 20 '12 at 05:19
  • 1
    filtering is perfectly plausible – David Heffernan Feb 20 '12 at 07:23