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. Creating a shortcut (LNK)

Creating a shortcut (LNK)

Scheduled Pinned Locked Moved C#
csharpdotnettoolsquestion
4 Posts 2 Posters 19 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.
  • Richard Andrew x64R Offline
    Richard Andrew x64R Offline
    Richard Andrew x64
    wrote on last edited by
    #1

    Hi, I'm working in .NET 8 (not .NET Framework). Trying to programmatically create a file system link (LNK file) in C#. I've added a reference to the Windows Script Host Object Model as detailed in many different online articles. However, I can't seem to find the correct Using statement to import the classes in that reference. When I say, "Using IWshRuntimeLibrary", it says it cannot resolve the type or namespace. What must I do to import the types in the Windows Script Host Object Model reference?

    The difficult we do right away... ...the impossible takes slightly longer.

    D 1 Reply Last reply
    0
    • Richard Andrew x64R Richard Andrew x64

      Hi, I'm working in .NET 8 (not .NET Framework). Trying to programmatically create a file system link (LNK file) in C#. I've added a reference to the Windows Script Host Object Model as detailed in many different online articles. However, I can't seem to find the correct Using statement to import the classes in that reference. When I say, "Using IWshRuntimeLibrary", it says it cannot resolve the type or namespace. What must I do to import the types in the Windows Script Host Object Model reference?

      The difficult we do right away... ...the impossible takes slightly longer.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      This worked fine for me in .NET 8:

      using IWshRuntimeLibrary;
      .
      .
      .
      WshShell shell = new();
      WshShortcut shortcut = shell.CreateShortcut(@"C:\Users\test\Desktop\Test.lnk");
      shortcut.TargetPath = @"C:\Windows";
      shortcut.Save();

      I didn't do anything other than set the reference to the Windows Script Host Library.

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak

      Richard Andrew x64R 1 Reply Last reply
      0
      • D Dave Kreskowiak

        This worked fine for me in .NET 8:

        using IWshRuntimeLibrary;
        .
        .
        .
        WshShell shell = new();
        WshShortcut shortcut = shell.CreateShortcut(@"C:\Users\test\Desktop\Test.lnk");
        shortcut.TargetPath = @"C:\Windows";
        shortcut.Save();

        I didn't do anything other than set the reference to the Windows Script Host Library.

        Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak

        Richard Andrew x64R Offline
        Richard Andrew x64R Offline
        Richard Andrew x64
        wrote on last edited by
        #3

        Yes, I found that code on the web. But VS is not able to resolve IWshRuntimeLibrary even though I added the reference. :((

        The difficult we do right away... ...the impossible takes slightly longer.

        D 1 Reply Last reply
        0
        • Richard Andrew x64R Richard Andrew x64

          Yes, I found that code on the web. But VS is not able to resolve IWshRuntimeLibrary even though I added the reference. :((

          The difficult we do right away... ...the impossible takes slightly longer.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Huh. You can try clearing the component caches. Quit VS and open the C:\Users\xxxx\AppData\Local\Microsoft\VisualStudio\_version_\ComponentModelCache folder and kill everything in it. Restart VS and see what happens. If that doesn't work, there's a cache folder for Roslyn too at C:\Users\xxxx\AppData\Local\Microsoft\VisualStudio\Roslyn. Wipe that one out too.

          Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak

          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