Solved

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

Posted on 1998-02-13
3
363 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access query that references subform 5 47
Exit a vb6 apps when a calling it apps closes 15 48
Add and format columns in vb6 7 57
Visual Studio 2005 text editor 10 38
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

770 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