Option Explicit
Private Declare Function ShellExecuteA Lib "shell32.dll" (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 BatchPath As String
Private Function ShellExec(ByVal Path As String, Optional ByVal WindowStyle As VbAppWinStyle = vbNormalFocus, Optional ByVal Operation As String = "open") As Boolean
ShellExec = (ShellExecuteA(0&, Operation, Path, vbNullString, vbNullString, WindowStyle) > 32)
End Function
Private Function FileExists(FileName As String) As Boolean
On Error Resume Next
FileExists = Not CBool(GetAttr(FileName) And (vbDirectory Or vbVolume))
End Function
Private Function RunBatch()
Call ShellExec(BatchPath, vbHide)
End Function
Private Sub Command1_Click()
BatchPath = Form1.Text1
If FileExists(BatchPath) Then RunBatch Else Call MsgBox("Datei existiert nicht. Pfad korrekt angegeben?", vbCritical)
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
If Command$ <> "" Then
BatchPath = Command$
If FileExists(BatchPath) Then RunBatch
Unload Me
End If
End Sub