Solved

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

Posted on 1998-02-13
3
350 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
Comment Utility
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
Comment Utility
 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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now