Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Start Menu Shortcuts in C#

Start Menu Shortcuts in C#

Scheduled Pinned Locked Moved C#
csharphelpquestion
4 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CyberKewl
    wrote on last edited by
    #1

    Is there an alternative way to create shortcuts in C# other than using the Wshell? Because everytime i include my app and distribute it to others, some people don't have the wscript.exe and even if they DID install it, they get this kind of error : "IWshShell3 failed". Are there any workarounds to this?

    S 1 Reply Last reply
    0
    • C CyberKewl

      Is there an alternative way to create shortcuts in C# other than using the Wshell? Because everytime i include my app and distribute it to others, some people don't have the wscript.exe and even if they DID install it, they get this kind of error : "IWshShell3 failed". Are there any workarounds to this?

      S Offline
      S Offline
      Stephane Rodriguez
      wrote on last edited by
      #2

      You can use the COM ShellLinkObject to create shortcuts, and this only requires shell32.dll. In an ideal world, things would be simple and you would just have to add a reference to shell32 in the VS.NET IDE, then start playing with the objects and interfaces. Unfortunately, the actual IShellLink interface is not declared in the shell32 namespace. You'll find ShellLinkObject and ShellLinkObjectClass but they are worthless. That's somewhat tough since you have to do the interop yourself, ie declare COM signatures. Here is how it goes :

      [ComImport, Guid("00021401-0000-0000-C000-000000000046")]
      class ShellLink
      {
      }

      [Guid("000214ee-0000-0000-c000-000000000046"),
      InterfaceType(ComInterfaceType.InterfaceIsDual)]
      interface IShellLinkA // Cannot list any base interfaces here
      {
      // Note that IUnknown Interface members are NOT listed here:

      void SetPath(string path);
      void SetDescription(string path);
      void Save(string where);

      ...
      }

      // and that's used with code like this :

      ShellLink c = new ShellLink();
      IShellLinkA i = (IShellLinkA) c;
      i.SetPath("ert");
      ...

      That's just the begin of the code. Be sure to read this reference MS article[^] (WIN32 C/C++ audience though).

      C 1 Reply Last reply
      0
      • S Stephane Rodriguez

        You can use the COM ShellLinkObject to create shortcuts, and this only requires shell32.dll. In an ideal world, things would be simple and you would just have to add a reference to shell32 in the VS.NET IDE, then start playing with the objects and interfaces. Unfortunately, the actual IShellLink interface is not declared in the shell32 namespace. You'll find ShellLinkObject and ShellLinkObjectClass but they are worthless. That's somewhat tough since you have to do the interop yourself, ie declare COM signatures. Here is how it goes :

        [ComImport, Guid("00021401-0000-0000-C000-000000000046")]
        class ShellLink
        {
        }

        [Guid("000214ee-0000-0000-c000-000000000046"),
        InterfaceType(ComInterfaceType.InterfaceIsDual)]
        interface IShellLinkA // Cannot list any base interfaces here
        {
        // Note that IUnknown Interface members are NOT listed here:

        void SetPath(string path);
        void SetDescription(string path);
        void Save(string where);

        ...
        }

        // and that's used with code like this :

        ShellLink c = new ShellLink();
        IShellLinkA i = (IShellLinkA) c;
        i.SetPath("ert");
        ...

        That's just the begin of the code. Be sure to read this reference MS article[^] (WIN32 C/C++ audience though).

        C Offline
        C Offline
        CyberKewl
        wrote on last edited by
        #3

        i put in this : [ComImport, Guid("00021401-0000-0000-C000-000000000046")] class ShellLink { } [Guid("000214ee-0000-0000-c000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsDual)] interface IShellLinkA // Cannot list any base interfaces here { void SetPath(string path); void SetDescription(string path); void SetIconLocation(string path, int index); void Save(string where); void SetWorkingDirectory(string path); } and called this: ShellLink c = new ShellLink(); IShellLinkA i = (IShellLinkA) c; i.SetPath(@"c:\test.txt"); i.Save(@"c:\test.lnk"); but it doesn't work (the shortcut doesn't appear). And i don't quite understand some of the stuff/code on the link you gave me (mainly because it's in C/C++). Any help would be greatly appreciated.

        S 1 Reply Last reply
        0
        • C CyberKewl

          i put in this : [ComImport, Guid("00021401-0000-0000-C000-000000000046")] class ShellLink { } [Guid("000214ee-0000-0000-c000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsDual)] interface IShellLinkA // Cannot list any base interfaces here { void SetPath(string path); void SetDescription(string path); void SetIconLocation(string path, int index); void Save(string where); void SetWorkingDirectory(string path); } and called this: ShellLink c = new ShellLink(); IShellLinkA i = (IShellLinkA) c; i.SetPath(@"c:\test.txt"); i.Save(@"c:\test.lnk"); but it doesn't work (the shortcut doesn't appear). And i don't quite understand some of the stuff/code on the link you gave me (mainly because it's in C/C++). Any help would be greatly appreciated.

          S Offline
          S Offline
          Stephane Rodriguez
          wrote on last edited by
          #4

          In my code snippet, IShellLink was declared as a dual interface, although, after I have double checked it, it's only a IUnknown interface. Here is the right declaration and code :

          [ComImport, Guid("00021401-0000-0000-C000-000000000046")]
          class SH
          {
          }

          [Guid("000214ee-0000-0000-c000-000000000046"),
          InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
          interface IShellLinkA // Cannot list any base interfaces here
          {
          // Note that IUnknown Interface members are NOT listed here:
          void GetPath(string pszFile,
          int cchMaxPath,
          IntPtr pfd,
          int fFlags);

          void GetIDList(IntPtr ppidl);

          void SetIDList(IntPtr pidl);

          void GetDescription(string pszName,
          int cchMaxName);

          void SetDescription(string pszName);

          void GetWorkingDirectory(string pszDir,
          int cchMaxPath);

          void SetWorkingDirectory(string pszDir);

          void GetArguments(string pszArgs, int cchMaxPath);

          void SetArguments(string pszArgs);

          IntPtr GetHotkey();

          void SetHotkey(int wHotkey);

          void Resolve(IntPtr hwnd,
          int fFlags);

          void SetPath(string pszFile);
          }

          //
          SH c = new SH();
          IShellLinkA i = (IShellLinkA) c;
          ...
          UCOMIPersistFile p = (UCOMIPersistFile) i;
          p.Save(@"c:\mylink.lnk",false);

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups