[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Ian Post

8/27/2010 12:45:00 AM

OK, I googled and found that there are at least three methods of
creating a shortcut that I can understand. The fourth I am not to sure
about.
I want to create a shortcut in the SendTo folder for my app. Command$
will have filenames to work with.

So what are the pros and cons of 2 and 3. I already read the cons of
1. And 4 may be beyond me without sample code to look through.

1) use fCreateShellLink (uses vb6stkit.dll).
2) use SHAddToRecentDocs to create the shortcut in the RECENT folder
then FileCopy to the desired folder.
3) use WSH to create the shortcut in the app folder then FileCopy it to
the folder.
4) use shelllnk.tlb ' i have no clue how to do this one.

All probably need the app creating the shortcut to Run as Admin on
Vista and 7. Yes?
Would be best to not have to use Run As Admin.


6 Answers

(nobody)

8/27/2010 1:08:00 AM

0

"BeeJ" <nospam@nowhere.com> wrote in message
news:i571pj$od9$1@speranza.aioe.org...
> 4) use shelllnk.tlb ' i have no clue how to do this one.

Not sure about shelllnk.tlb, but you can download a type library that
defines ShellLink from this page:

http://www.mvps.org/emorcillo/en/code/vb6/i...

It's in the first file "OLELIB.TLB - OLE interfaces & functions v1.7". When
you distribute your app, make sure that you don't include either the TLB
file, nor Shell32.dll!


Ian Post

8/27/2010 2:05:00 AM

0

Nobody submitted this idea :
> "BeeJ" <nospam@nowhere.com> wrote in message
> news:i571pj$od9$1@speranza.aioe.org...
>> 4) use shelllnk.tlb ' i have no clue how to do this one.
>
> Not sure about shelllnk.tlb, but you can download a type library that defines
> ShellLink from this page:
>
> http://www.mvps.org/emorcillo/en/code/vb6/i...
>
> It's in the first file "OLELIB.TLB - OLE interfaces & functions v1.7". When
> you distribute your app, make sure that you don't include either the TLB
> file, nor Shell32.dll!

I got it all loaded and active code-wise for instantiation but I have
no clue as to all the parameters. Searched for a sample but so far
found nothing useful. I know how to get the SendTo folder so step one
is done. But need help on step two.
Why is this better than the other methods?


Mayayana

8/27/2010 2:38:00 AM

0

Shelllnk.tlb is on the VS CD, disk 2. That came
up just a couple of days ago. There's also sample
code on the CD. Eduardo Morcillo has his own way
of doing things. If you use his TLB you'll probably
need to also use his code.

Following is a compact adaptation of the VS code
that creates a shortcut. It requires shelllnk.tlb. You
call it like so:

LRet = CreateShortcut("C:\Windows\Desktop\Bees App.lnk" _
"C:\Program Files\Bees Folder\Bee.exe" _
"Bee.exe" _
"C:\Program Files\Bees Folder\Bee.exe", 0

' begin code -----------

Private Const MAX_PATH = 255
Private Const SHOWNORMAL As Long = 5


Public Function CreateShortcut(sLnkFile As String, sTargetPath As String,
sTargetDesc As String, _
IconPath As String, IconIdx As Long) As Long
'-- sLnkFile is path for shortcut, ending in LNK
'-- sTargetPath is path of shortcut target
'-- sTargetDesc is description of target, such as filename
'-- IconPath is source of icon for shortcut, IconIdx is icon index.
'--to leave these out set iconpath as "" and iconidx as 0.
Dim LNKOb As ShellLinkA ' An explorer
IShellLinkA(Win 95/Win NT) instance
Dim cPersistFile As IPersistFile ' An explorer
IPersistFile instance
CreateShortcut = 1 '--failed.
If ((sLnkFile = "") Or (sTargetPath = "")) Then Exit Function '
Validate min. input requirements.
On Error GoTo ErrHandler
Set LNKOb = New ShellLinkA ' Create new IShellLink
interface
Set cPersistFile = LNKOb ' Implement lnkob's
IPersistFile interface

With LNKOb
.SetPath sTargetPath
If (sTargetDesc <> "") Then .SetDescription sTargetDesc ' Set
shortcut description - basename
If (IconPath <> "") Then .SetIconLocation IconPath, IconIdx ' Set
shortcut icon location & index
.SetShowCmd SHOWNORMAL ' Set shortcut's startup mode
(min,max,normal)
End With

LNKOb.Resolve 0, SLR_UPDATE
cPersistFile.Save StrConv(sLnkFile, vbUnicode), 0 ' Unicode conversion
hack... This must be done!
CreateShortcut = 0 ' Return Success
ErrHandler:

Set cPersistFile = Nothing
Set LNKOb = Nothing
End Function

'------------- end code -------------------

If you're interested I also have 2 updated versions of
the PDW Setup1.exe file. Both create a Desktop shortcut
and use the code above. One version is just updated
and cleaned up. The other version also eliminates the
need for setup.exe. See here:

http://www.jsware.net/jsware/v...

Personally I don't see any reason not to use vb6stkit.dll,
as long as you install it and don't just assume the PDW
left a copy behind. But I don't know of code for that. And
the method above works fine. vb6stkit.dll methods are
just wrappers.
Using SHAddToRecentDocs sounds hokey to me. There's
no need of it. Using WSH is even more hokey. Also, on
some systems WSH may be disabled. WSH is for local use
with VBScript. It's not part of the API.


unknown

8/27/2010 3:42:00 AM

0

Try this (you just have to change the destination path):

Sub CreateShortCut(DestDir As String, Programa As String, Descripcion As
String)
On Local Error Resume Next
'*******************************************************************************' *' * Shortcut related methods.' *Dim WSHShellSet WSHShell = CreateObject("WScript.Shell")Dim MyShortcut, MyDesktop, DesktopPath' Read desktop path using WshSpecialFolders object' Create a shortcut object on the desktopSet MyShortcut = WSHShell.CreateShortCut(GetPath(CSIDL_STARTUP) & "\" &Descripcion & ".lnk")' Set shortcut object properties and save itMyShortcut.TargetPath = WSHShell.ExpandEnvironmentStrings(DestDir &Programa)MyShortcut.WorkingDirectory = WSHShell.ExpandEnvironmentStrings(DestDir)MyShortcut.WindowStyle = 4MyShortcut.IconLocation = WSHShell.ExpandEnvironmentStrings(DestDir &Programa & ", 0")MyShortcut.SaveEnd Sub"BeeJ" <nospam@nowhere.com> escribió en el mensajenews:i571pj$od9$1@speranza.aioe.org...> OK, I googled and found that there are at least three methods of creatinga shortcut that I can understand. The fourth I am not to sure about.> I want to create a shortcut in the SendTo folder for my app. Command$will have filenames to work with.>> So what are the pros and cons of 2 and 3. I already read the cons of 1.And 4 may be beyond me without sample code to look through.>> 1) use fCreateShellLink (uses vb6stkit.dll).> 2) use SHAddToRecentDocs to create the shortcut in the RECENT folder thenFileCopy to the desired folder.> 3) use WSH to create the shortcut in the app folder then FileCopy it tothe folder.> 4) use shelllnk.tlb ' i have no clue how to do this one.>> All probably need the app creating the shortcut to Run as Admin on Vistaand 7. Yes?> Would be best to not have to use Run As Admin.>>

Kevin Provance

8/27/2010 4:19:00 AM

0

No. Bad. See Maya's post.

One of my error trapping and tracing libraries has a system info class,
which lists startup applications. I needed to read lnk files in the startup
folder. I used Ednamo's TLB to do it. No dist required. The referenced
code is compiled into your app. Source is also available if you want to
study typelibs. It's powerful stuff if you can learn the syntax.



"Gary" <nospam@nospam.com> wrote in message
news:%23dmSDnZRLHA.5172@TK2MSFTNGP06.phx.gbl...
: Try this (you just have to change the destination path):
:
: Sub CreateShortCut(DestDir As String, Programa As String, Descripcion As
: String)
: On Local Error Resume Next
:
'*******************************************************************************'
*' * Shortcut related methods.' *Dim WSHShellSet WSHShell =
CreateObject("WScript.Shell")Dim MyShortcut, MyDesktop, DesktopPath' Read
desktop path using WshSpecialFolders object' Create a shortcut object on the
desktopSet MyShortcut = WSHShell.CreateShortCut(GetPath(CSIDL_STARTUP) & "\"
&Descripcion & ".lnk")' Set shortcut object properties and save
itMyShortcut.TargetPath = WSHShell.ExpandEnvironmentStrings(DestDir
&Programa)MyShortcut.WorkingDirectory =
WSHShell.ExpandEnvironmentStrings(DestDir)MyShortcut.WindowStyle =
4MyShortcut.IconLocation = WSHShell.ExpandEnvironmentStrings(DestDir
&Programa & ", 0")MyShortcut.SaveEnd Sub"BeeJ" <nospam@nowhere.com> escribió
en el mensajenews:i571pj$od9$1@speranza.aioe.org...> OK, I googled and found
that there are at least three methods of creatinga shortcut that I can
understand. The fourth I am not to sure about.> I want to create a shortcut
in the SendTo folder for my app. Command$will have filenames to work
with.>> So what are the pros and cons of 2 and 3. I already read the cons
of 1.And 4 may be beyond me without sample code to look through.>> 1) use
fCreateShellLink (uses vb6stkit.dll).> 2) use SHAddToRecentDocs to create
the shortcut in the RECENT folder thenFileCopy to the desired folder.> 3)
use WSH to create the shortcut in the app folder then FileCopy it tothe
folder.> 4) use shelllnk.tlb ' i have no clue how to do this one.>> All
probably need the app creating the shortcut to Run as Admin on Vistaand 7.
Yes?> Would be best to not have to use Run As Admin.>>
:

BeeJ

8/27/2010 6:24:00 AM

0

Found the Shelllnk.tlb on Disk 3 and will give this a try.
Looks like the best way.
I think I understand your example.
Thanks!