Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

FindExecutable (shell32)
 
.
Summary

C# Signature:

[DllImport("shell32.dll")]
static extern IntPtr FindExecutable(string lpFile, string lpDirectory, [Out] StringBuilder lpResult);

VB Signature:

<DllImport("shell32.dll")> _
Private Shared Function FindExecutable(ByVal lpFile As String, ByVal lpDirectory As String, ByRef lpResult As StringBuilder) As IntPtr
Private Shared Function FindExecutable(ByVal lpFile As String, ByVal lpDirectory As String, <Out()> ByVal lpResult As StringBuilder) As IntPtr
End Function

VBA Signature:

Private Declare Function FindExecute Lib "shell32.dll" Alias _
"FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory _
As String, ByVal lpResult As String) As Long

User-Defined Types:

None.

Notes:

1) When using VB, one cannot place the declaration for FindExecutable within

the code portion of a form. If one needs to search for an executable from

within a form, though, it is easy enough to open a module and place the

declaration there. From the form code, make a call to a function in the

module. Within the module function, execute FindExecutable and return any

results to the form routine. steveapub@pineclifftech.com

2) Make sure the following references are available:

Imports System.Runtime.InteropServices
Imports System.Text

Tips & Tricks:

Error Codes that can be returned:

    Public Enum FindExecutableErrorCodes
    ''' <summary>The specified file was not found.</summary>
    SE_ERR_FNF = 2

    ''' <summary>There is no application associated with the given file name extension. This error will also be returned if you attempt to print a file that is not printable. </summary>
    SE_ERR_NOASSOC = 31

    ''' <summary>There was not enough memory to complete the operation.</summary>
    SE_ERR_OOM = 8
    End Enum

Sample Code:

Please add some!!

Alternative Managed API:

Do you know one? Please contribute it!

Documentation

********** Win32API.cs **********

using System;

using System.Text;

using System.Runtime.InteropServices;

namespace QuickTool

{

    public class Win32API
    {
        [DllImport("shell32.dll", EntryPoint="FindExecutable")]
        public static extern long FindExecutableA(
            string lpFile, string lpDirectory, StringBuilder lpResult);

        public static string FindExecutable(
            string pv_strFilename)
        {
            StringBuilder objResultBuffer =
                new StringBuilder(1024);
            long lngResult = 0;

            lngResult =
                FindExecutableA(pv_strFilename,
                string.Empty, objResultBuffer);

            if(lngResult >= 32)
            {
                return objResultBuffer.ToString();
            }

            return string.Format(
                "Error: ({0})", lngResult);
        }
    }

}

********************************

******** Form1.cs ********

private void mnuDynamic_Click(object sender, System.EventArgs e)

{

    MenuItem theMenuItem = (MenuItem) sender;
    MessageBox.Show(Win32API.FindExecutable(theMenuItem.Text));

}

**********************************

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions