Start or Restart an exe from within your Appl.
starts an exe from within your application. But if the exe is already loaded, it becomes the focus! Normaly it starts with the poor shell-Command again and again... // IN GERMAN: Startet eine EXE aus Deiner VB-Applikation. Wenn Die EXE jedoch schon einmal gestartet wurde, wird sie lediglich fokusiert(!). Normalerweise würde sie wieder und wieder gestartet werden, wenn sie zuvor vom User nicht geschlossen wurde!
API Declarations
Option Explicit
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Rate Start or Restart an exe from within your Appl.
(2(2 Vote))
Private Sub Command1_Click()
Dim Handle As Long
' the FindWindow-API needs the Caption-Name of the exe-File (e.g. Calculator for the Calc.exe!)
' Handle = FindWindow(vbNullString, "")
Handle = FindWindow(vbNullString, "Calculator") ' Is the exe already loaded?
' *! im deutschen Windows muss bei diesem Beispiel statt "Calculator" das Wort "Rechner" stehen!!!
If Handle = 0 Then ' _if the Handle becomes 0 then START the EXE-File
Handle = Shell("CALC.EXE", 1)
Else ' _if fires a Handle, the exe is there! Let´s focus it...
ShowWindow Handle, 0 ' Hide the EXE (huh! Where is the exe???)
ShowWindow Handle, 1 ' Show the EXE (now it becomes the Focus!!!)
End If
End Sub
Start or Restart an exe from within your Appl. Comments
No comments yet — be the first to post one!
Post a Comment