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
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