PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : CreateProcess() - Prozess wird gestartet und gleich wieder beendet


Diabolo
31.12.2004, 17:01
Moin zusammen,

noch auf die Schnelle im alten Jahr mal ne Frage :

ich habe mir mit CreateProcess() einen Prozess starten lassen unter WinXP als Admin. Der Prozess wird aber nur für einen kurzen Moment gestartet und anschließend gleich wieder beendet. Wie erreiche ich es, daß er dauerhaft bestehen bleibt ?

Hier der Code im Formular:

Private Sub cmdCreateProcess_Click()

Dim lngRetCreProc As Long
Dim strFile As String
Dim Sec_Att As SECURITY_ATTRIBUTES
Dim Sec_Att_2 As SECURITY_ATTRIBUTES
Dim ST_UP_INFO As STARTUPINFO
Dim Proc_Info As PROCESS_INFORMATION

On Error GoTo ErrHandler

With Sec_Att
.nLength = Len(Sec_Att)
.bInheritHandle = True
End With

With Sec_Att_2
.nLength = Len(Sec_Att_2)
End With

With ST_UP_INFO
.cb = Len(ST_UP_INFO)
.dwFlags = STARTF_USESHOWWINDOW
.wShowWindow = SW_SHOWNORMAL
End With

strFile = "D:\Programme\Internet Explorer\iexplore.exe"

lngRetCreProc = CreateProcess(strFile, cmdline, Sec_Att, Sec_Att_2, _
1, HIGH_PRIORITY_CLASS, 0&, vbNullString, ST_UP_INFO, Proc_Info)

If lngRetCreProc > 0 Then
WaitForSingleObject Proc_Info.hProcess, 5000
frmCreateRemoteThread.lstInfo.AddItem "Process Created successfully"
frmCreateRemoteThread.lstInfo.AddItem "Process-Handle : " & Proc_Info.hProcess
frmCreateRemoteThread.lstInfo.AddItem "Process-ID : " & Proc_Info.dwProcessId
frmCreateRemoteThread.lstInfo.AddItem "Thread-Handle : " & Proc_Info.hThread
frmCreateRemoteThread.lstInfo.AddItem "Thread-ID : " & Proc_Info.dwThreadId
lngProcHandle = Proc_Info.hProcess
Else
frmCreateRemoteThread.lstInfo.AddItem "Error : " & Err.LastDllError & " _ " & Err.Description
End If

Exit Sub

ErrHandler:
MsgBox Err.LastDllError

End Sub
Private Sub Form_Load()
frmCreateRemoteThread.cmdCreateProcess.Value = True
End Sub


Hier der Code im Modul : (reine Funktionen / Konstanten / Typen)

Public lngProcHandle As Long
Public Declare Function CreateRemoteThread Lib "kernel32.dll" ( _
ByVal hProcess As Long, _
ByRef lpThreadAttributes As SECURITY_ATTRIBUTES, _
ByVal dwStackSize As Long, _
ByRef lpStartAddress As Long, _
ByRef lpParameter As Any, _
ByVal dwCreationFlags As Long, _
ByRef lpThreadId As Long) As Long
Public 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
Public Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Public Declare Function WaitForSingleObject Lib "kernel32.dll" ( _
ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long

Public Declare Sub ExitProcess Lib "kernel32" ( _
ByVal uExitCode As Long)
Public Declare Function GetExitCodeProcess Lib "kernel32" ( _
ByVal hProcess As Long, _
lpExitCode As Long) As Long
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 Byte
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type


Hier (http://home.arcor.de/pascalscholtes/Downloads/CreateProcess.rar)ist das Projekt im .rar-Format.

Danke im Voraus und guten Rutsch,

Diabolo


butterkeks
31.12.2004, 17:40
Welchen Wert hat "cmdline" im cmdbutton sub?

hab nur kurz drüber geschaut, aber scheinbar haste "cmdline" net definiert und wegen fehlender Parameter endet das Prog direkt...?

Diabolo
01.01.2005, 13:46
cmdLine hat keinen Wert, das war nur ein Versuch. Vorher hab ich da einen vbNullString übergeben, aber leider geht es trotzdem nicht.


Herr Bahlsen, Sie waren eine meiner Hoffnungen hier. :p

butterkeks
01.01.2005, 17:46
Ich hab mal einen CreateProcess Aufruf aus nem alten Prog kopiert und etwas aufbereitet; Vlt. funzt es bei dir so:

Option Explicit

' deklarationen stehen im Modul

Private Sub Form_Load()
Dim s1 As SECURITY_ATTRIBUTES, s2 As SECURITY_ATTRIBUTES
Dim si As STARTUPINFO
Dim pi As PROCESS_INFORMATION

s1.nLength = Len(s1)
s2.nLength = Len(s2)
si.cb = Len(si)

CreateProcess _
vbNullString, _
"D:\Programme\Internet Explorer\iexplore.exe", _
s1, s2, False, HIGH_PRIORITY_CLASS, _
0&, vbNullString, si, pi

CreateProcess _
vbNullString, _
"D:\Programme\Internet Explorer\iexplore.exe http://wtf.de", _
s1, s2, False, HIGH_PRIORITY_CLASS, _
0&, vbNullString, si, pi
End Sub

Der Code sollte 2 mal den IE öffnen, einmal mit dem standart URL und einmal auf http://wtf.de (mal aus dem Finger gezogen; keine Werbung, falls der URL überhaupt auf etwas zeigt)

Wie du siehst, hab ich den ersten Parameter einfach auf vbNullString gesetzt und das ganze stattdessen in den 2. Parameter gepackt, wie es in der API Referenz als Alternative vorgeschlagen wird (wo da der Sinn ist, kan nich mri net vorstellen).

Diabolo
01.01.2005, 18:17
Aaaah, das ist mal einen Versuch wert. Gleich mal testen. *freu*:)

Diabolo
02.01.2005, 13:20
Nee, also das wars dann leider auch nicht. Also wie gesagt, was ich nicht verstehe ist folgendes : der Prozess wird gestartet, er trägt mir auch die PID ins Listenfeld ein, aber dann wird der Prozess gleich wieder beendet.

Diabolo
07.01.2005, 17:12
Nur der Information halber :


der Prozess kann nur gestartet werden, wenn der aufrufende Prozess die notwendigen Rechte hat.

In diesem Fall :

PROCESS_VM_READ
PROCESS_VM_WRITE
PROCESS_CREATE_THREAD


Das war alles. So einfach ist die Welt.