Hi
Hallo
ich kenn mich mit ShellExecute nicht aus.
Hast du da ein Beispiel für???
Hmm, das ist rel. Simple. Weiter unten schreibe ich dir ein kleines bsp dafür 
Nehmen wir an die Exe-Datei heisst cremer.exe! und die Datei
Test.cod
Der Pfad kann leider unterschiedlich sein, weil das vom
Rechner abhängig ist,
d.h. er muß vorher gesucht werden auf c: d: e:
Ok, da suche einfach die Datei. Ich poste dir weiter eine klasse die du einbinden kannst. Die rufst dann 3 mal auf. erst fürs Laufwerk c dann Laufwerk d und dann Laufwerk e
Falls das Programm überhaupt nicht gefunden wird, soll die
Datei mit Notepad geöffnet werden.
Deklariere einfach eine Variable Prg als String. Dieser weise „“ zu. Dann suche die Datei cremer.exe. Sollte sie gefunden werden, weisse prg den Pfad hinzu. Solltest du nun alle Laufwerke dursucht haben und es wird keine Datei gefunden, so ist prg="" dann weisst du welches Prog du nehmen musst 
Cod deswegen, weil ich abundan auch eine Meldung bekommen
habe, das die Endung nicht definiert ist und Viren enthalten
könnte.
Das klingt arg nach einer einstellungssache deines Virenprogs 
So eine Meldung soll natürlich nicht erscheinen.
Ist das schwer, das so zu realisieren???
Nein ist es nicht *zwinker*
So nun die Codeschnipsel Werner
Die Klasse zum suchen cFindFile
Option Explicit
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32\_FIND\_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32\_FIND\_DATA) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
Private Const MAX\_PATH = 260
Private Const MAXDWORD = &HFFFF
Private Const INVALID\_HANDLE\_VALUE = -1
Private Const MyUnhandledError = 9999
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Type WIN32\_FIND\_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String \* MAX\_PATH
cAlternate As String \* 14
End Type
Public Enum FileFlag
FILE\_ATTRIBUTE\_READONLY = &H1
FILE\_ATTRIBUTE\_HIDDEN = &H2
FILE\_ATTRIBUTE\_SYSTEM = &H4
FILE\_ATTRIBUTE\_DIRECTORY = &H10
FILE\_ATTRIBUTE\_ARCHIVE = &H20
FILE\_ATTRIBUTE\_NORMAL = &H80
FILE\_ATTRIBUTE\_TEMPORARY = &H100
FILE\_ATTRIBUTE\_ALLTYPES = &H1B7
FILE\_ATTRIBUTE\_ALLTYPES\_WITHOUT\_DIR = &H1A7
End Enum
Private mvarsSearchpath As String
Private mvarsFileToFind As String
Private mvarsInclSubfolders As Boolean
Private mvarsFileFlag As FileFlag
Public Event MatchFound(ByVal sFilename As String, \_
ByVal sFilePath As String, \_
ByVal sFiledate As Date, \_
ByVal sFilesize As Long, \_
ByVal sLastAccess As Date, \_
ByVal sLastWrite As Date, \_
ByVal sShortName As String)
Public Event StopSearch(Cancel As Boolean)
Public Event Searchpath(Path As String)
Public Event SearchFile(File As String)
Public Event SearchEnd()
Private Sub Class\_Initialize()
On Error resume next
sFileFlag = FILE\_ATTRIBUTE\_ALLTYPES
sInclSubfolders = True
Exit Sub
End Sub
Public Sub sStartSearch()
On Error goto error
Dim lFileToFind As String, lSearchpath As String, FileName As String
Dim ShortName As String, DirName As String, DirNames() As String
Dim DirCount As Integer, nDir As Integer, Cont As Integer, i As Integer
Dim Filesize As Long, hSearch As Long
Dim Filedate As Date, LastAccess As Date, LastWrite As Date
Dim lInclSubfolders As Boolean, bCancel As Boolean
Dim sDate As SYSTEMTIME
Dim lFileFlag As FileFlag
Dim WFD As WIN32\_FIND\_DATA
lFileToFind = sFileToFind
lFileFlag = sFileFlag
lSearchpath = sSearchpath
lInclSubfolders = sInclSubfolders
If Right(lSearchpath, 1) "\" Then lSearchpath = lSearchpath & "\"
nDir = 0
DirCount = 0
ReDim DirNames(nDir)
Cont = True
bCancel = False
hSearch = FindFirstFile(lSearchpath & "\*", WFD)
RaiseEvent Searchpath(lSearchpath)
If hSearch INVALID\_HANDLE\_VALUE Then
Do While Cont
DirName = Left$(WFD.cFileName, InStr(WFD.cFileName, vbNullChar) - 1)
If (DirName ".") And (DirName "..") Then
If (WFD.dwFileAttributes And vbDirectory) = FileFlag.FILE\_ATTRIBUTE\_DIRECTORY Then
DirNames(nDir) = DirName
DirCount = DirCount + 1
nDir = nDir + 1
ReDim Preserve DirNames(nDir)
End If
End If
RaiseEvent SearchFile(DirName)
Cont = FindNextFile(hSearch, WFD)
DoEvents
Loop
Cont = FindClose(hSearch)
End If
hSearch = FindFirstFile(lSearchpath & lFileToFind, WFD)
RaiseEvent Searchpath(lSearchpath)
Cont = True
If hSearch INVALID\_HANDLE\_VALUE Then
While Cont
FileName = Left$(WFD.cFileName, InStr(WFD.cFileName, vbNullChar) - 1)
If (FileName ".") And (FileName "..") Then
If (WFD.dwFileAttributes Or lFileFlag) = lFileFlag Then
Filesize = (WFD.nFileSizeHigh \* MAXDWORD) + WFD.nFileSizeLow
FileTimeToSystemTime WFD.ftCreationTime, sDate
With sDate
Filedate = CDate(.wDay & "." & .wMonth & "." & .wYear & " " & .wHour & ":" & .wMinute & ":" & .wSecond)
End With
FileTimeToSystemTime WFD.ftLastAccessTime, sDate
With sDate
LastAccess = CDate(.wDay & "." & .wMonth & "." & .wYear & " " & .wHour & ":" & .wMinute & ":" & .wSecond)
End With
FileTimeToSystemTime WFD.ftLastWriteTime, sDate
With sDate
LastWrite = CDate(.wDay & "." & .wMonth & "." & .wYear & " " & .wHour & ":" & .wMinute & ":" & .wSecond)
End With
ShortName = Left$(WFD.cAlternate, InStr(WFD.cAlternate, vbNullChar) - 1)
RaiseEvent MatchFound(FileName, lSearchpath, Filedate, Filesize, LastAccess, LastWrite, ShortName)
End If
End If
Cont = FindNextFile(hSearch, WFD)
DoEvents
Wend
Cont = FindClose(hSearch)
End If
If lInclSubfolders Then
If nDir \> 0 Then
For i = 0 To nDir - 1
RaiseEvent StopSearch(bCancel)
If bCancel Then Exit Sub
sSearchpath = lSearchpath & DirNames(i)
sStartSearch
Next i
End If
End If
Exit Sub
error:
RaiseError MyUnhandledError, "cFindFile:sStartSearch Method", "Fehler bei sStartSearch"
End Sub
Public Property Let sFileFlag(ByVal vData As FileFlag)
On Error goto error
mvarsFileFlag = vData
Exit Property
error:
RaiseError MyUnhandledError, "cFindFile:sFileFlag Property Let", "Fehler bei sFileFlag Property Let"
End Property
Public Property Get sFileFlag() As FileFlag
On Error GoTo error
sFileFlag = mvarsFileFlag
Exit Property
error:
RaiseError MyUnhandledError, "cFindFile:sFileFlag Property Get", "Fehler bei sFileFlag Property Get"
End Property
Public Property Let sInclSubfolders(ByVal vData As Boolean)
On Error GoTo error
mvarsInclSubfolders = vData
Exit Property
error:
RaiseError MyUnhandledError, "cFindFile:sInclSubfolders Property Let", "Fehler bei sInclSubfolders Property Let"
End Property
Public Property Get sInclSubfolders() As Boolean
On Error GoTo error
sInclSubfolders = mvarsInclSubfolders
Exit Property
error:
"Property")
RaiseError MyUnhandledError, "cFindFile:sInclSubfolders Property Get", "Fehler bei sInclSubfolders Property Get"
End Property
Public Property Let sFileToFind(ByVal vData As String)
On Error GoTo error
mvarsFileToFind = vData
Exit Property
error:
RaiseError MyUnhandledError, "cFindFile:sFileToFind Property Let", "Fehler bei sFileToFind Property Let"
End Property
Public Property Get sFileToFind() As String
On Error GoTo error
sFileToFind = mvarsFileToFind
Exit Property
error:
RaiseError MyUnhandledError, "cFindFile:sFileToFind Property Get", "Fehler bei sFileToFind Property Get"
End Property
Public Property Let sSearchpath(ByVal vData As String)
On Error GoTo error
mvarsSearchpath = vData
Exit Property
error:
RaiseError MyUnhandledError, "cFindFile:sSearchpath Property Let", "Fehler bei sSearchpath Property Let"
End Property
Public Property Get sSearchpath() As String
On Error GoTo error
sSearchpath = mvarsSearchpath
Exit Property
error:
RaiseError MyUnhandledError, "cFindFile:sSearchpath Property Get", "Fehler bei sSearchpath Property Get"
End Property
Private Sub RaiseError(ErrorNumber As Long, Source As String, strErrorText As String)
On Error resume next
Err.Raise ErrorNumber, Source, strErrorText
Exit Sub
End Sub
Private Sub Class\_Terminate()
On Error resume next
RaiseEvent SearchEnd
Exit Sub
End Sub
Aufrufen tust du deine Suche wiefolgt, Einfach in der Form folgenden Code rein
Option Explicit
Private WithEvents nSearch As cFindFile
Private bCancel As Boolean
Private Sub Suche(LW as String)
On Error resume next
bCancel = False
With nSearch
.sFileFlag = FILE\_ATTRIBUTE\_ALLTYPES
.sFileToFind = "cremer.exe"
.sInclSubfolders = True
.sSearchpath = lw
.sStartSearch
End With
End Sub
Private Sub nSearch\_StopSearch(Cancel As Boolean)
On Error resume next
If bCancel Then
Cancel = bCancel 'Scan beenden
DoEvents
End If
End Sub
Private Sub nSearch\_MatchFound(ByVal sFilename As String, ByVal sFilePath As String, ByVal sFiledate As Date, ByVal sFilesize As Long, ByVal sLastAccess As Date, ByVal sLastWrite As Date, ByVal sShortName As String)
On Error resume next
prg=sFilePath & sFilename
bcancel=true
End Sub
Wenn ein File Namens cremer.exe gefunden wird, so wird die suche beendet. Nun weisst du schon einmal wie du an dem Pfad vom cremer.exe rankommst. Starten kannst du das Programm ja wie gesagt über shellexecute. Wie ? Schau hier *zwinker*
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 Sub Command1\_Click()
On Error Resume Next
Dim retval As Long
If Trim(prg) = "" Then
'Notpad starten
'Achte darauf das der Pfad zu Notepad stimmt!
retval = ShellExecute(Me.hwnd, "Open", "c:\winnt\notepad.exe", "f:\test.dat", "", 1)
Else
'Cremer.exe starten und als Parameter test.cod übergeben
'Achte dabei darauf das test.Cod den richtigen Pfad aufweisst
retval = ShellExecute(Me.hwnd, "Open", prg, "Test.cod", "", 1)
End If
End Sub
Mfg Werner
Mfg Alex