Link to home
Start Free TrialLog in
Avatar of toddlengnick
toddlengnick

asked on

VB6 Shortcut to .exe put on desktop of Windows 7 and Vista machines

Please help me put a shortcut to the following file on the desktop of a Windows 7 and Vista machine:

c:\Program Files\Rorschach Scoring Trainer\Scoring Trainer.exe

Thanks!
Avatar of toddlengnick
toddlengnick

ASKER

for clarity's sake: I need to know how to program this to happen in VB6...
I used to use the Visual Basic 6.0 Package and Deployment Wizard to define all the files to distribute.
I then use the target directory of %USERPROFILE%\desktop to save the icon too..
Avatar of Karen
oh dear...it's me again :)

Replace with your own values in the following, and choose from either "this user" or "all users"...

Public Sub CreateShortcut()
Dim WSHShell         As Object
Dim ShellLink        As Object
Dim UserDesktopPath  As String
Dim EXEPath          As String
Dim ShortcutTitle    As String

    Set WSHShell = CreateObject("WScript.Shell")
    ' To create a shortcut for the current user ONLY:
    UserDesktopPath = WSHShell.SpecialFolders("Desktop")
    ' To create a shortcut for ALL USERS:
    UserDesktopPath = WSHShell.SpecialFolders("AllUsersDesktop")
    EXEPath = "C:\PathToYourFile\YourFileName.exe"
    ShortcutTitle = "TEST"
   
    Set ShellLink = WSHShell.CreateShortcut(UserDesktopPath & "\" & ShortcutTitle & ".lnk")
    ShellLink.TargetPath = EXEPath
    ShellLink.IconLocation = EXEPath
    ShellLink.WorkingDirectory = EXEPath
    ShellLink.Save
   
    Set ShellLink = Nothing
    Set WSHShell = Nothing
End Sub
Snowberry,


This works great in XP... will this also work with Windows 7 and Vista?

Thank you!
ASKER CERTIFIED SOLUTION
Avatar of Karen
Karen
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Got it - this works great - thank you for all your help!