Solved

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

Posted on 1998-02-13
3
377 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
VB6 - Compare and highlight cell not the same 3 63
Help me. 3 79
Send outlook email from VBS Script 2 67
Formula problem with Excel attachment 6 45
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

752 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