Solved

Executing .lnk, .pif, .exe, .com etc from vb5/win32

Posted on 1998-02-13
3
370 Views
Last Modified: 2012-06-27
Hi,
I have in my file listbox the items form desktop.  Now when is select any application i want to execute - Desktop may contain shortcuts, actual files or associated files.
How do i get the shortcuts file to run (.lnk)

thanks
0
Comment
Question by:msali
  • 2
3 Comments
 
LVL 5

Expert Comment

by:dirtdart
ID: 1457024
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long


ShellExecute will run any file by finding the program associated with it and executing it.  hwnd is the window handle of your main window. lpOperation in this case will be "open".  lpFile is the path and filename.  lpParameters are any command line paramenters you need.  lpDirectory is the directory that your program will run in.  nShowCmd is how the window will show.  SW_SHOW will show the window normal.  SW_HIDE will hide the window.  SW_SHOWDEFAULT will show it in its default manner.  These and others are listed in the Win32API.txt
0
 
LVL 4

Accepted Solution

by:
yowkee earned 10 total points
ID: 1457026
 Use ShellExecute to run program or document with program associated with it. Passed "open" or "explore" in second parameter of ShellExecute to open or explore the file.
 
  For shortcut to program or folder, pass Null string to second parameter (lpOperation). For example, a shorcut "C:\Testwin.lnk" point to folder "C:\windows\command", call Shellexecute to open it:

  ShellExecute(0,, vbNullString, "C:\testwin.lnk", "", "", 1)

  Hope this help.
0
 
LVL 4

Expert Comment

by:yowkee
ID: 1457028
Hi, msali,

  The method worked in my machine. I have a DUN entry in start menu folder and a shortcut to "My Documents" in directory C:\. And it worked for this two entry.
  Do you specify the filename with extension .lnk?
  Let see whether we do the same thing. I make a shortcut to My Documents under root directory C: called "My Documents.lnk". Then I execute it with:
   lstrFolder = "C:\My Documents.lnk"
   call ShellExecute(0, vbNullString, lstrFolder, "", "", 1)
  Could you try it? Thanx.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question