fddima обратиться по имени
Суббота, 24 Июля 2004 г. 15:37 (ссылка)
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
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
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As SECURITY_ATTRIBUTES, lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Private Const INFINITE = &HFFFF ' Infinite timeout
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Function SpawnChildProcess(filename As String, cmdline As String, wait As Boolean) As Boolean
Dim sa As SECURITY_ATTRIBUTES
Dim pi As PROCESS_INFORMATION
Dim si As STARTUPINFO
With sa
.nLength = Len(sa)
.lpSecurityDescriptor = 0
.bInheritHandle = 0
End With
With si
.cb = Len(si)
.dwFlags = 0
End With
If CreateProcess(filename, cmdline, sa, sa, 0, 0, 0, vbNullString, si, pi) = 0 Then
SpawnChildProcess = False
Exit Function
Else
If wait = True Then
If WaitForSingleObject(pi.hProcess, INFINITE) = 0 Then
End If
End If
End If
SpawnChildProcess = True
End Function
Private Sub Command1_Click()
SpawnChildProcess "c:\winnt\system32\cmd.exe", "", True
End Sub