2

How can I change at runtime the caption in the right-click context menu for the taskbar button for my program? I mean the text circled in red here.

enter image description here

The caption appears to be taken from the assembly title. I need to alter the caption dynamically at runtime from code. I have one EXE which the users "see" as a number of different apps - it reads data files at runtime and then customizes its appearance massively, including the window caption. I need to also customize the caption in this right-click menu. There's no single caption that covers everything. I'm willing to consider P/Invoke calls to the Windows API if necessary.

This is a WinForms .Net 4.5.2 program, screenshot is Windows 7.

Community
  • 1
  • 1
MarkJ
  • 30,070
  • 5
  • 68
  • 111
  • See [Changing .Net assembly name at runtime](http://stackoverflow.com/q/15504870/719186). – LarsTech Jan 20 '16 at 17:25
  • @LarsTech I looked at that, it said it was impossible to change the assembly name dynamically. My hope is that it is however possible to somehow change the menu caption in the context menu, maybe through something in the Windows API (which controls the taskbar and does not AFAIK deal with assemblies which are a .Net concept) – MarkJ Jan 20 '16 at 17:28
  • check this out see if it helps I am sure if there's a will there's a way http://stackoverflow.com/questions/1948014/how-to-handle-form-caption-right-click – MethodMan Jan 20 '16 at 17:54
  • @methodman Thanks but that's about clicking on the form caption, not the taskbar button – MarkJ Jan 21 '16 at 08:07

2 Answers2

2

I have a solution for you, but not sure it will work for you

I will make some assumptions to drive home my solution

  1. It is a winforms project built using visual studio
  2. You haven't modified your original Program.cs file
  3. All your assembly attributes are in AssembyInfo.cs

Program.cs typically looks like this

using System;
using System.Windows.Forms;

static class Program {
    [STAThread]
    static void Main() {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }
}

One way to deal with it is to build your app as a Class Library sans the Program.cs, let's call it App.dll. Then merge your code from Program.cs and AssemblyInfo.cs (only relevant portions) into a single file and let's call it App.cs. You should auto-generate App.cs either with a separate script or via App.cs itself Now build App.cs referencing App.dll generating App.exe. This App.exe should work exactly like your current executable.

Once all this is established, you can already see where we are going with this.

Now, when your App.exe start's up and reads the config to make changes, you should auto-generate App.cs with a different AssemblyTitle like below

[assembly: AssemblyTitle("MyAssembly")]

and generate App-Flavor1.exe, and spawn that process and exit out of App.exe

Vikhram
  • 4,294
  • 1
  • 20
  • 32
  • +1 Because it's creative and it should work. Dynamically compiling and building the EXE at runtime on the user's machine might be overkill for us though. If no-one comes up with a better answer I will accept this. – MarkJ Jan 27 '16 at 14:56
  • OK I accept this answer! Sounds like it could work, and no-one else has provided an answer... – MarkJ Feb 03 '16 at 17:18
0

Long time ago but...

You can modify it in the "Registry Editor".

  1. Open the "Registry Editor" (in windows 10, click on START > type reg and you will have it on the search results).
  2. Click on the "Edit" menu > "Find". A dialog box will be opened.
  3. Type the name of the executable file of your program (e.g. "MyAppName.exe") > "Find Next".
  4. Now you should see property which name ends with "FriendlyAppName" and the value is the current caption name. Right click on it and then click on "Modify".
  5. Type your desired caption name in the "Value" textbox. > OK.
  6. If you have several copies of this app in your PC then go over all of them using the "Edit > Find Next" menu item and modify them all.

Be careful not to modify any other values in the Registry Editor, it may harm your PC well being.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Boazt
  • 1