locked
Diffrentiate application shortcuts & document shortcuts RRS feed

  • Question

  • is there any way to differentiate application shortcuts and user created document shortcuts using c#
    Friday, March 13, 2009 5:20 AM

Answers

  • When you register your file type, you can set the DefaultIcon.

    See: http://msdn.microsoft.com/en-us/library/cc144158(VS.85).aspx

    Per http://msdn.microsoft.com/en-us/library/ms682212(VS.85).aspx, the icon is supposed to be embedded in an .exe.  This is an issue because Visual Studio will only embed one Win32 icon resource in the .exe.  However, I believe that it will work if you just put the path and filename for a standalone .ico file, with no comma or icon index number.

    If you want to go down the path of embedding multiple Win32 icons:

    To make a Win32 .res file with your icons, do the following:

    1.  Click File, New File, General, Native Resource Template.
    2.  Click Edit, Add Resource, Icon.
    3.  Use the Import button to pick an existing file.
    4.  Repeat for additional icons.
    5.  Click File, Save As.
    6.  In the Save As Type dropdown, select 32-bit Resource File (*.res).
    7.  Save your file with the .res extension.
    8.  Click Project, Your Project Properties, Application tab.
    9.  Click the Resource File radio button.
    10.  Select the .res file you just saved.
    11.  Build your project.
    • Proposed as answer by Harry Zhu Thursday, March 19, 2009 7:11 AM
    • Marked as answer by Harry Zhu Friday, March 20, 2009 1:26 AM
    Saturday, March 14, 2009 5:07 PM
  • I am not sure this is the right way but showing it anyway

    1. Add Reference to com called Windows Script Host Object Model (Project Add Reference)

    using IWshRuntimeLibrary;

    WshShell shell = new WshShell();
                IWshShortcut sc = (IWshShortcut)shell.CreateShortcut(@"C:\test\my  Shortcut.lnk");
                string ext= System.IO.Path.GetExtension(sc.TargetPath);
                if (ext == ".com" || ext == ".exe")  // make a list of executable here or look at GetBinaryType
                {
                    MessageBox.Show("Executables");
                }

    Arjun Paudel
    • Proposed as answer by Harry Zhu Thursday, March 19, 2009 7:11 AM
    • Marked as answer by Harry Zhu Friday, March 20, 2009 1:26 AM
    Sunday, March 15, 2009 4:36 PM
  • I think this link will help you get multiple icons embedded into the executable

    Embedding Multiple Icons into .NET Executables

    • Proposed as answer by Harry Zhu Thursday, March 19, 2009 7:11 AM
    • Marked as answer by Harry Zhu Friday, March 20, 2009 1:26 AM
    Monday, March 16, 2009 3:31 AM

All replies

  • When you register your file type, you can set the DefaultIcon.

    See: http://msdn.microsoft.com/en-us/library/cc144158(VS.85).aspx

    Per http://msdn.microsoft.com/en-us/library/ms682212(VS.85).aspx, the icon is supposed to be embedded in an .exe.  This is an issue because Visual Studio will only embed one Win32 icon resource in the .exe.  However, I believe that it will work if you just put the path and filename for a standalone .ico file, with no comma or icon index number.

    If you want to go down the path of embedding multiple Win32 icons:

    To make a Win32 .res file with your icons, do the following:

    1.  Click File, New File, General, Native Resource Template.
    2.  Click Edit, Add Resource, Icon.
    3.  Use the Import button to pick an existing file.
    4.  Repeat for additional icons.
    5.  Click File, Save As.
    6.  In the Save As Type dropdown, select 32-bit Resource File (*.res).
    7.  Save your file with the .res extension.
    8.  Click Project, Your Project Properties, Application tab.
    9.  Click the Resource File radio button.
    10.  Select the .res file you just saved.
    11.  Build your project.
    • Proposed as answer by Harry Zhu Thursday, March 19, 2009 7:11 AM
    • Marked as answer by Harry Zhu Friday, March 20, 2009 1:26 AM
    Saturday, March 14, 2009 5:07 PM
  • I am not sure this is the right way but showing it anyway

    1. Add Reference to com called Windows Script Host Object Model (Project Add Reference)

    using IWshRuntimeLibrary;

    WshShell shell = new WshShell();
                IWshShortcut sc = (IWshShortcut)shell.CreateShortcut(@"C:\test\my  Shortcut.lnk");
                string ext= System.IO.Path.GetExtension(sc.TargetPath);
                if (ext == ".com" || ext == ".exe")  // make a list of executable here or look at GetBinaryType
                {
                    MessageBox.Show("Executables");
                }

    Arjun Paudel
    • Proposed as answer by Harry Zhu Thursday, March 19, 2009 7:11 AM
    • Marked as answer by Harry Zhu Friday, March 20, 2009 1:26 AM
    Sunday, March 15, 2009 4:36 PM
  • I think this link will help you get multiple icons embedded into the executable

    Embedding Multiple Icons into .NET Executables

    • Proposed as answer by Harry Zhu Thursday, March 19, 2009 7:11 AM
    • Marked as answer by Harry Zhu Friday, March 20, 2009 1:26 AM
    Monday, March 16, 2009 3:31 AM