January 30th, 2003, 03:13 AM
Creating Shortcuts with VB
I currently have an app that runs under win9X, one of the features is to create shortcuts on the desktop, I know need the program on winXP but the API call I use no longer works!
Private Declare Function OSfCreateShellLink Lib "vb6stkit.dll" Alias "fCreateShellLink" _
(ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, _
ByVal lpstrLinkPath As String, ByVal lpstrLinkArguments As String, _
ByVal fPrivate As Long, ByVal sParent As String) As Long
Do you know why this is? is there a different line of code, the machine I am testing it on has all the right DLLs but it just wont work
Thanks for any help
January 30th, 2003, 04:08 AM
January 30th, 2003, 05:20 AM
Thanks for the site but that is the code i already have, it doesnt work on XP, i think it is to do with the first arguement, in all the info sources i have found it has had "..\..\desktop" but the desktop path in xp is different! any more help would be greatly appreciated!
January 30th, 2003, 09:06 AM
There is another way to create a shortcut. To make the following code works, add a reference to Windows Script Host Model:
Note that you'll have to use GetSpecialFolders to know where is the ShortCut and change "C:\TestLink.lnk" by the desktop folder AND the name of the link
'code modified from
Dim WshShell As New WshShell
Dim oShellLink As WshShortcut
'Create and save the shortcut
'Here, it is important the the extension end by .lnk
Set oShellLink = WshShell.CreateShortcut( "C:\TestLink.lnk" )
'Shortcut to which file (can be anything, .exe, .doc, ...)
.TargetPath = "C:\WINNT\SYSTEM32\calc.exe"
.WindowStyle = 1
.IconLocation = "C:\WINNT\SYSTEM32\calc.exe, 0"
.Arguments = ""
Set WshShell = Nothing
Set oShellLink = Nothing
January 31st, 2003, 05:20 AM
That worked a treat thanx
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.