Menemukan File Executable dengan Perintah API

Tuesday, May 31, 2011 | 11:25 AM|

Pendeklarasian Perintah API :
API Explanation
The FindExecutable function retrieves the name and handle to the executable (.EXE) file associated with the specified filename.

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


· lpFile
Pointer to a null-terminated string specifying a filename. This can be a document or executable file.

· lpDirectory
Pointer to a null-terminated string specifying the default directory.

· lpResult
Pointer to a buffer to receive the filename when the function returns. This filename is a null-terminated string specifying the executable file started when an "open" association is run on the file specified in the lpFile parameter.

When FindExecutable returns, the lpResult parameter may contain the path to the DDE server started if no server responds to a request to initiate a DDE conversation.

Kode dalam Form :


Const MAX_FILENAME_LEN = 260
Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, _ ByVal lpDirectory As String, ByVal lpResult As String) As Long

Private Sub Form_Load()
Dim i As Integer, s2 As String
Const sFile = "C:\\Windows\\Readme.txt"

'Check if the file exists
If Dir(sFile) = "" Or sFile = "" Then
MsgBox "File not found!", vbCritical
Exit Sub
End If
'Create a buffer
s2 = String(MAX_FILENAME_LEN, 32)
'Retrieve the name and handle of the executable, associated with this file
i = FindExecutable(sFile, vbNullString, s2)
If i > 32 Then
MsgBox Left$(s2, InStr(s2, Chr$(0)) - 1)
Else
MsgBox "No association found !"
End If
End Sub

0 comments: