6

I've got an app that downloads an .exe to a temporary folder and runs it with the System.Diagnostics.Process class. So far I've run two different apps with it. One is a console app, the other is a full windows app. The windows app has its icon in the taskbar/titlebar, but the console app only has a generic application icon. If I navigate to the temp folder the console app does have its icon; and running it "by hand" (double-clicking in explorer) also gives it the correct icon.

What could be the cause of this?

Additional info: The ProcessStartInfo class does not offer any flags concerning the icon. I'm running the process with UseShellExecute=true and ErrorDialog=true. Also, the windows app is started maximized but the console app is minimized (as specified by the WindowStyle member of ProcessStartInfo). Finally, the icon for the console app only includes a 32x32x4bpp icon, while the windows app has a large selection of different formats.

Added: I gave the downloaded app a proper icon. Still no go. :(

Added 2: Oh, right, Windows 7 x64.

Update: Just tried some more experiments. I created a new C++ (unmanaged, not .NET) application with just "press any key to continue" in it and gave it an icon. The icon shows up normally in explorer, and when I run it from explorer, the icon is in the window title bar.

However, when I start the application from Visual studio (via F5 or Ctrl-F5); or when I run the application via another .NET application and Process.Start() - the icon doesn't appear. Why?

Vilx-
  • 104,512
  • 87
  • 279
  • 422

3 Answers3

3

I'm not sure why this happens, but a work-around is to set the WorkingDirectory in the ProcessStartInfo structure to the directory of the EXE.

This works whether UseShellExecute is true or not.

Vince
  • 379
  • 1
  • 7
  • this alteration fixed it in my case! – anion Mar 23 '16 at 12:48
  • 1
    If anyone has found another fix for this then please share it because it's very frustrating.. Win 10. – David Oct 06 '17 at 02:16
  • I was trying to run console application from the PowerShell command prompt: `Start-process -FilePath "C:\path\to\my.exe"` and this application didn't have the application icon in the taskbar. If I run the my.exe through the double-click, an icon shown correctly. The workaround above worked for me: when I pass an additional -WorkingDirectory argument it works as expected: `Start-process -WorkingDirectory "C:\path\to\" -FilePath "C:\path\to\my.exe"` – Roganik Dec 06 '18 at 08:30
0

I suppose that downloadable app previously didnt have an icon. But now is has, so may be the windows has buffered icon and you just need to reboot. Im not sure. I just tryed to run one console app from another and icons has displayed. But when I changed icon and recompile applications I saw old icon until I have reboot. So its obviously windows problem

Anton Semenov
  • 6,227
  • 5
  • 41
  • 69
  • I doubt it. The temp folder is with a random name. Windows doesn't need to touch its icon until it's run - and then it's already fully downloaded. – Vilx- Mar 03 '11 at 11:43
0

This code shows console application with user defined icon normally:

        Process p = new Process();

        p.StartInfo = new ProcessStartInfo("ConsoleApplication1.exe")
            {
                UseShellExecute = true,
                ErrorDialog = true,
                WindowStyle = ProcessWindowStyle.Minimized
            };

        p.Start();

Icon file used in my ConsoleApplication1.exe includes all resolutions.

Therefore I think problem source may be in:

  1. There isn't correct resolution image in ico-file (But why when you start it manually app looks normally on tray?)
  2. Security permissions
acoolaum
  • 2,132
  • 2
  • 15
  • 24
  • That's pretty much the code I use. No idea why the difference. Maybe indeed the icon resolutions? – Vilx- Mar 03 '11 at 11:59
  • @Vilx-, I think icon resolution (but why when you start it manually app looks normally on tray) or may be security permissions? Try to launch test console app with good icon from your winforms app. – acoolaum Mar 03 '11 at 12:03
  • I just tried it with a new unmanaged C++ app - the icon doesn't show up. – Vilx- Mar 14 '11 at 10:17