vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Mails senden, abrufen und decodieren - ganz easy ;-)  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

Fortgeschrittene Programmierung
Re: Synchroner Shell Befehl und kein Einfrieren des Programms 
Autor: Dirk
Datum: 10.12.10 13:26

Hier mal der Code, mit dem ich eine Anwendung starte und auf Beendigung selbiger warte, vielleicht hilft es dir weiter:

Public Const INFINITE As Long = -1&
Public Const NORMAL_PRIORITY_CLASS As Long = &H20&
 
 
Private Declare Function CreateProcess Lib "kernel32.dll" Alias _
  "CreateProcessA" ( _
    ByVal lpApplicationName As String, _
    ByVal lpCommandLine As String, _
    ByRef lpProcessAttributes As SECURITY_ATTRIBUTES, _
    ByRef lpThreadAttributes As SECURITY_ATTRIBUTES, _
    ByVal bInheritHandles As Long, _
    ByVal dwCreationFlags As Long, _
    ByRef lpEnvironment As Any, _
    ByVal lpCurrentDriectory As String, _
    ByRef lpStartupInfo As STARTUPINFO, _
    ByRef lpProcessInformation As PROCESS_INFORMATION _
  ) As Long
 
Private Declare Function CreateProcessByNum Lib "kernel32.dll" Alias _
  "CreateProcessA" ( _
    ByVal lpApplicationName As String, _
    ByVal lpCommandLine As String, _
    ByVal lpProcessAttributes As Long, _
    ByVal lpThreadAttributes As Long, _
    ByVal bInheritHandles As Long, _
    ByVal dwCreationFlags As Long, _
    ByRef lpEnvironment As Any, _
    ByVal lpCurrentDriectory As String, _
    ByRef lpStartupInfo As STARTUPINFO, _
    ByRef lpProcessInformation As PROCESS_INFORMATION _
  ) As Long
 
Private Declare Function WaitForSingleObject Lib "kernel32.dll" ( _
    ByVal hHandle As Long, _
    ByVal dwMilliseconds As Long _
  ) As Long
 
Private Declare Function CloseHandle Lib "kernel32.dll" ( _
    ByVal hObject As Long _
  ) As Long
 
 
Private Type SECURITY_ATTRIBUTES
  nLength As Long
  lpSecurityDescriptor As Long
  bInheritHandle As Long
End Type
 
Public Type STARTUPINFO
  cb As Long
  lpReserved As Long
  lpDesktop As Long
  lpTitle As Long
  dwX As Long
  dwY As Long
  dwXSize As Long
  dwYSize As Long
  dwXCountChars As Long
  dwYCountChars As Long
  dwFillAttribute As Long
  dwFlags As Long
  wShowWindow As Integer
  cbReserved2 As Integer
  lpReserved2 As Long
  hStdInput As Long
  hStdOutput As Long
  hStdError As Long
End Type
 
Public Type PROCESS_INFORMATION
  hProcess As Long
  hThread As Long
  dwProcessID As Long
  dwThreadID As Long
End Type
 
Public Sub ExecuteAndWait( _
    cmdline As String, _
    Optional ByVal waitMs As Long = INFINITE _
  )
 
  Dim NameOfProc    As PROCESS_INFORMATION
  Dim NameStart     As STARTUPINFO
  Dim sa            As SECURITY_ATTRIBUTES
  Dim x             As Long
 
  On Error Resume Next
 
  sa.nLength = Len(sa)
  sa.bInheritHandle = True
 
  NameStart.cb = Len(NameStart)
  x = CreateProcess( _
          cmdline, _
          vbNullString, _
          sa, sa, _
          True, _
          NORMAL_PRIORITY_CLASS, _
          0&, 0&, _
          NameStart, NameOfProc _
        )
 
  x = CreateProcessByNum( _
          cmdline, _
          vbNullString, _
          0, 0, _
          True, _
          NORMAL_PRIORITY_CLASS, _
          ByVal 0&, _
          vbNullString, _
          NameStart, _
          NameOfProc _
        )
 
  Debug.Assert Err = 0
 
  If waitMs <= 0 Then
    waitMs = INFINITE
  End If
  x = WaitForSingleObject(NameOfProc.hProcess, waitMs)
 
  x = CloseHandle(NameOfProc.hProcess)
 
  Debug.Assert Err = 0
 
End Sub

Gruß
Dirk

--
?Get it right the first time

alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Synchroner Shell Befehl und kein Einfrieren des Programms1.823salim_aliya08.12.10 14:22
Re: Synchroner Shell Befehl und kein Einfrieren des Programm...1.230Dirk08.12.10 14:55
Re: Synchroner Shell Befehl und kein Einfrieren des Programm...1.358salim_aliya08.12.10 15:08
Re: Synchroner Shell Befehl und kein Einfrieren des Programm...1.181Dirk10.12.10 13:26
Re: Synchroner Shell Befehl und kein Einfrieren des Programm...1.330Dirk10.12.10 13:59
Re: Synchroner Shell Befehl und kein Einfrieren des Programm...1.170salim_aliya10.12.10 17:06

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel