Home All Groups Group Topic Archive Search About

Placing a .lnk file on the desktop

Author
31 Jul 2006 4:32 AM
genojoe
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?

Author
31 Jul 2006 5:57 AM
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
Author
31 Jul 2006 7:35 AM
Herfried K. Wagner [MVP]
"genojoe" <geno***@discussions.microsoft.com> schrieb:
>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>

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
31 Jul 2006 12:36 PM
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


genojoe wrote:
Show quoteHide quote
> 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?