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