Placing a .lnk file on the desktop

G

Guest

I am using the following code to locate the desktop folder. After doing
this, I would like to place a shortcut on the desktop that opens a specific
folder. How do I create the .lnk file for a folder called "C:\Temp"? Help
of any type would be appreciated.

Dim regPath As RegistryKey =
Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")

If Not regPath Is Nothing Then
sPath = (regPath.GetValue("Desktop")).ToString
End If

What next?
 
S

Steven Nagy

Hi,

I've done this before... but don't have the code in front of me.
Create a shortcut the normal way. Then in command prompt, navigate to
the folder where the shortcut exists. Use MORE or something similar to
show the contents of the .lnk file. You will see the text that
constructs the link. Then, on your desktop, create a text file
something.txt and enter the same data as your link. Then, all you need
to do is rename the .txt as a .lnk and it becomes a shortcut.

So everything I just said to do manually, you can have your application
do as well. I deployed my shortcuts as .dat files and then later
renamed them as .lnk files AFTER copying them to the user's desktop.

Naturally you can use .NET to programatically create the text that goes
into your text file, thus allowing you to create a dynamic shortcut on
the fly.

Sorry for not having code present.

SN
 
H

Herfried K. Wagner [MVP]

genojoe said:
I am using the following code to locate the desktop folder. After doing
this, I would like to place a shortcut on the desktop that opens a
specific
folder. How do I create the .lnk file for a folder called "C:\Temp"?
Help
of any type would be appreciated.

Dim regPath As RegistryKey =
Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Explorer\Shell
Folders")

You may want to use 'Environment.GetFolderPath' instead.
If Not regPath Is Nothing Then
sPath = (regPath.GetValue("Desktop")).ToString
End If

What next?

<URL:http://www.msjogren.net/dotnet/eng/samples/dotnet_shelllink.asp>
<URL:http://vbaccelerator.com/article.asp?id=4301>
 
H

HKSHK

Hello genojoe,

Based on http://msdn2.microsoft.com/en-us/library/fywyxt64.aspx please
find the solution below:

Dim Shell As Object, Link As Object
Dim DesktopPath As String

Shell = CreateObject("WScript.Shell")

DesktopPath = Shell.SpecialFolders("Desktop")

Link = Shell.CreateShortcut(DesktopPath & "\MyTestLink.lnk")

Link.Arguments = "C:\WINDOWS\regopt.log"

link.Description = "test shortcut"

link.HotKey = "CTRL+ALT+SHIFT+X"

Link.IconLocation = "C:\Windows\system32\SHELL32.dll,1"

Link.TargetPath = "c:\windows\notepad.exe"

link.WindowStyle = 3

Link.WorkingDirectory = "c:\Windows"

link.Save()


Best Regards,

HKSHK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top