
February 15th, 2006, 09:41 AM
|
|
Contributing User
|
|
Join Date: Sep 2004
Posts: 108
Time spent in forums: 11 h 16 m 54 sec
Reputation Power: 5
|
|
as module add
Code:
'Danke sehr http://www.vbarchiv.net/vbapi/ShellExecute.php
'lpOperation The operation to perform on lpFile. This can be one of the following strings, although other options are possible, depending on the file being acted upon:
'"explore" If lpFile is a path name, open it in a Windows Explorer window.
'"open" Open lpFile using its associated program. Opening an executable file runs it. This is the default action if none is specified.
'"print" Print lpFile using its associated program.
'lpFile The name of the file to open, print, execute, or whatever is specified by lpVerb.
'lpParameters Additional parameters to use to perform the action. This would typically be additional command-line options to use, especially when running an executable file.
Private 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
Private Const SW_HIDE = 0
Private Const SW_MAXIMIZE = 3
Private Const SW_MINIMIZE = 6
Private Const SW_NORMAL = 1
Private Const SW_SHOW = 5
Private Const SW_RESTORE = 9
Private Const SW_SHOWMAXIMIZED = 3
Private Const SW_SHOWMINIMIZED = 2
Private Const SW_SHOWMINNOACTIVE = 7
Private Const SW_SHOWNA = 8
Private Const SW_SHOWNOACTIVATE = 4
Private Const SW_SHOWNORMAL = 1
Private Const ERROR_BAD_FORMAT = 11&
Private Const SE_ERR_ACCESSDENIED = 5
Private Const SE_ERR_ASSOCINCOMPLETE = 27
Private Const SE_ERR_DDEBUSY = 30
Private Const SE_ERR_DDEFAIL = 29
Private Const SE_ERR_DDETIMEOUT = 28
Private Const SE_ERR_DLLNOTFOUND = 32
Private Const SE_ERR_FNF = 2
Private Const SE_ERR_NOASSOC = 31
Private Const SE_ERR_OOM = 8
Private Const SE_ERR_PNF = 3
Private Const SE_ERR_SHARE = 26
Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
(ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
Private Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" _
(ByVal lpString As Any) As Long
' FindExecutable Konstanen
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Public Sub Execute(HWND As Long, PathName As String, FileName As String)
Dim Retval As Long
Dim ASSOCIATEDPROG As String
ASSOCIATEDPROG = FindAssociatedProg(PathName, FileName)
MsgBox ASSOCIATEDPROG
Retval = ShellExecute(HWND, "open", Chr(34) & ASSOCIATEDPROG & Chr(34), _
Chr(34) & PathName & "\" & FileName & Chr(34), Chr(34) & PathName & Chr(34), SW_SHOWNORMAL)
Select Case Retval
Case SE_ERR_NOASSOC
MsgBox "Datei ist nicht Assizoiert", vbInformation, "Fehler"
Exit Sub
Case SE_ERR_PNF
MsgBox "Pfad wurde nicht gefunden", vbInformation, "Fehler"
Exit Sub
Case SE_ERR_FNF
MsgBox "Datei wurde nicht gefunden", vbInformation, "Fehler"
Exit Sub
Case 8, 26, 32, 28, 29, 30, 27, 5, 11 ' alle anderen Fehler
Exit Sub
End Select
End Sub
Function FindAssociatedProg(PathName As String, FileName As String) As String
Dim Retval As Long, Puffer As String
Puffer = Space(256)
Retval = FindExecutable(FileName, PathName, Puffer)
If Retval = 42 Then FindAssociatedProg = Left$(Puffer, lstrlen(Puffer))
End Function
In your program
Execute Me.HWND, File1.Path, File1.FileName
|