Люди выручайте. Использую функцию Create Process, задаю приоритет и все такое(ииспользуя API-Guide :)). А дальше что. Вот я передаю ей адрес программы, а она сама не открывается(окна проги нет).
Да, кстати, а почему именно CreateProcess решил использовать, для просто ты можно WinExec, ShellExecute, на худой конец Shell VB'шный, он хоть PID процесса возвратит
Почему именно это, потому что в этой функции можно изменить много параметров до запуска самого эгзешника или .....
Вот код, посмотрите плиз, где ошибка:
Const INFINITE = &HFFFF
Const STARTF_USESHOWWINDOW = &H1
Private Enum enSW
SW_HIDE = 0
SW_NORMAL = 1
SW_MAXIMIZE = 3
SW_MINIMIZE = 6
End Enum
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId 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 Byte
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private Enum enPriority_Class
NORMAL_PRIORITY_CLASS = &H20
IDLE_PRIORITY_CLASS = &H40
HIGH_PRIORITY_CLASS = &H80
End Enum
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 Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Function SuperShell(ByVal App As String, ByVal WorkDir As String, dwMilliseconds As Long, ByVal start_size As enSW, ByVal Priority_Class As enPriority_Class) As Boolean
 im pclass As Long
 im sinfo As STARTUPINFO
 im pinfo As PROCESS_INFORMATION
'Not used, but needed
 im sec1 As SECURITY_ATTRIBUTES
 im sec2 As SECURITY_ATTRIBUTES
'Set the structure size
sec1.nLength = Len(sec1)
sec2.nLength = Len(sec2)
sinfo.cb = Len(sinfo)
'Set the flags
sinfo.dwFlags = STARTF_USESHOWWINDOW
'Set the window's startup position
sinfo.wShowWindow = start_size
'Set the priority class
pclass = Priority_Class
'Start the program
If CreateProcess(vbNullString, App, sec1, sec2, False, pclass, _
0&, WorkDir, sinfo, pinfo) Then
'Wait
WaitForSingleObject pinfo.hProcess, dwMilliseconds
SuperShell = True
Else
SuperShell = False
End If
End Function
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
'Set the dialog's title
CDBox.DialogTitle = "Choose an EXEC-File ..."
'Error when canceled
CDBox.CancelError = True
'Set the dialog's filter
CDBox.Filter = "EXEC-Files (*.exe)|*.exe|All files (*.*)|*.*"
'Show the 'Open File'-dialog
CDBox.ShowOpen
'Execute the program
SuperShell CDBox.filename, Left$(CDBox.filename, Len(CDBox.filename) - Len(CDBox.FileTitle)), 0, SW_NORMAL, HIGH_PRIORITY_CLASS
End
End Sub
Да и 1 возвращает и хандл, ПИД окна все передает.
А самого окна нету. Вот еще некоторые exe, бат запускает и окно есть, а большинство всетаки нет. А мне нужно, чтобы все
А может у тебя в приложении, которе ты запускашь, окна нету? не, ну отвечают же на вопрос "почему картошка не выросла" фразой "забыли посадить" )))))))))))
Еще раз отвечаю почему использую именно эту функцию, а не остальные потому что благодаря ней можно задать приложению приоритет, фокус, нач. положение, секьюрити атрибуты и т.д. и т.п.
Возвращает и ПИД и хандл окна(все короче).
Окна у тех прог, что запускаю есть. К примеру беру Download Master(кто знает поймет, что это не консольное приложение )))
ПРОШУ ПОМОЩИ Администратов и всех кто может реально указать на ошибку. Заблаговременно благодарен !!!!
Const INFINITE = &HFFFF
Const STARTF_USESHOWWINDOW = &H1
Private Enum enSW
SW_HIDE = 0
SW_NORMAL = 1
SW_MAXIMIZE = 3
SW_MINIMIZE = 6
End Enum
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId 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 Byte
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private Enum enPriority_Class
NORMAL_PRIORITY_CLASS = &H20
IDLE_PRIORITY_CLASS = &H40
HIGH_PRIORITY_CLASS = &H80
End Enum
Private Declare Function CreateProcess Lib "kernel32" 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, ByVal lpEnvironment As String, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Function SuperShell(ByVal App As String, ByVal WorkDir As String, dwMilliseconds As Long, ByVal start_size As enSW, ByVal Priority_Class As enPriority_Class) As Boolean
Dim pclass As Long
Dim sinfo As STARTUPINFO
Dim pinfo As PROCESS_INFORMATION
sinfo.cb = Len(sinfo)
'Set the flags
'sinfo.dwFlags = STARTF_USESHOWWINDOW
'Set the window's startup position
'sinfo.wShowWindow = vbNormal
'Set the priority class
'pclass = Priority_Class
'Start the program
If CreateProcess(vbNullString, App, 0, 0, 0, 0, vbNullString, WorkDir, sinfo, pinfo) Then
'Wait
WaitForSingleObject pinfo.hProcess, dwMilliseconds
SuperShell = True
Else
SuperShell = False
End If
End Function
Private Sub Form_Load()
'Execute the program
SuperShell "notepad.exe", vbNullString, 0, SW_NORMAL, HIGH_PRIORITY_CLASS
End
End Sub
Кто-хоть в параметр Any отсылает 0 без ByVal !?
см (lpEnviromenrs)