Гость
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / VB 6 ShellExecuteEx не возвращает hProcess / 2 сообщений из 2, страница 1 из 1
14.07.2019, 12:17
    #39837206
surbanec
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
VB 6 ShellExecuteEx не возвращает hProcess
Здравствуйте. с помощью ShellExecuteEx пытаюсь запустить процесс, процесс успешно запускается и выполняет свою работу,но HProcess остается равен = 0
Код: vbnet
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
Private Declare Function WaitForSingleObject Lib "kernel32.dll" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

Private Type SHELLEXECUTEINFO
    cbSize As Long
    fMask As Long
    hwnd As Long
    lpVerb As String
    lpFile As String
    lpParameters As String
    lpDirectory As String
    nShow As Long
    hInstApp As Long
    ' fields
    lpIDList As Long
    lpClass As String
    hkeyClass As Long
    dwHotKey As Long
    hIcon As Long
    hProcess As Long
End Type
Private Const WAIT_TIMEOUT As Long = 258&
Private Declare Function ShellExecuteEx Lib "shell32.dll" (ByRef lpExecInfo As SHELLEXECUTEINFO) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long

Function unrar()
Dim lpExecInfo As SHELLEXECUTEINFO
lpExecInfo.cbSize = Len(lpExecInfo)
lpExecInfo.fMask = &HC Or &H0&
lpExecInfo.lpFile = tempfol & "\u.exe"
lpExecInfo.hwnd = 0&
lpExecInfo.lpVerb = ""
lpExecInfo.lpParameters = "x -y -o+ """ & "u1.rar" & """ """ & tempfol & Chr(34)
lpExecInfo.lpDirectory = tempfol
lpExecInfo.nShow = 0
lpExecInfo.hInstApp = 0
ShellExecuteEx lpExecInfo
If lpExecInfo.hProcess = 0 Then MsgBox "Ошибка целостности пакета", vbCritical: GoTo endd
Do
DoEvents
If WaitForSingleObject(lpExecInfo.hProcess, 100) <> WAIT_TIMEOUT Then Exit Do
Loop
endd:
CloseHandle lpExecInfo.hProcess
End Function



в чем может быть проблема?
...
Рейтинг: 0 / 0
15.07.2019, 03:21
    #39837292
Дмитрий77
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
VB 6 ShellExecuteEx не возвращает hProcess
surbanecно HProcess остается равен = 0
в чем может быть проблема?
SHELLEXECUTEINFOA structure
SEE_MASK_NOCLOSEPROCESS (0x00000040)Use to indicate that the hProcess member receives the process handle. This handle is typically used to allow an application to find out when a process created with ShellExecuteEx terminates. In some cases, such as when execution is satisfied through a DDE conversation, no handle will be returned. The calling application is responsible for closing the handle when it is no longer needed.
Код: vbnet
1.
.fMask = SEE_MASK_NOCLOSEPROCESS 

На, лови. Сравнишь, родишь.
Код: vbnet
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
Public Function ExecuteProcess(ByVal FilePath As String, ByVal hwnd As Long, _
 ByVal nShow As Long, Optional lpParameters As String = "", _
 Optional LaunchElevated As Boolean = False, _
 Optional useDoEvent As Boolean = False) As ExecuteStatus 'nShow - напр.SW_SHOWNORMAL
 
  'useDoEvent -использует цикл с DoEvent вместо WaitForSingleObject
 
  Dim ExecInfo As SHELLEXECUTEINFO
  Dim lExitCode As Long

  With ExecInfo
    ' Set up the structure.
    .cbSize = Len(ExecInfo)
    .fMask = SEE_MASK_NOCLOSEPROCESS ' SEE_MASK_DEFAULT
    .lpFile = FilePath
    .nShow = nShow
    .lpDirectory = ExtractDirectoryFromPath(FilePath)
    .lpParameters = lpParameters
    .hwnd = hwnd

    ' On Microsoft Windows Vista and later, one can use runas instead of Open, in order to execute the
    ' process as an elevated process. In that case, the user will be asked whether he or she wants to
    ' run the process as an administrator.
    If LaunchElevated = True Then
      .lpVerb = "runas"
    Else
      .lpVerb = "Open"
    End If
  End With

  If ShellExecuteEx(ExecInfo) Then
    If useDoEvent Then
      Do
        'Get the status of the process
        GetExitCodeProcess ExecInfo.hProcess, lExitCode
        DoEvents
        'Loop while the process is active
      Loop While lExitCode = STILL_ACTIVE
    Else
      Call WaitForSingleObject(ExecInfo.hProcess, INFINITE)
    End If
    If GetExitCodeProcess(ExecInfo.hProcess, lExitCode) <> 0 Then
      If lExitCode = 0 Then
        ExecuteProcess = res_OK
      Else
        ExecuteProcess = res_FAILED
      End If
    Else
      ExecuteProcess = res_FAILED
    End If
    Call CloseHandle(ExecInfo.hProcess)
  Else
    ExecuteProcess = res_CANCEL
  End If
End Function


Код: vbnet
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
'мои константы -результат запущенного другого процесса, OK, Failed либо Cancel (например не стали вводить пароль администратора)
Public Enum ExecuteStatus
  res_OK
  res_FAILED
  res_CANCEL
End Enum

'Shell Structures

' fMask - Flags that indicate the content and validity of the other structure members
Public Const SEE_MASK_DEFAULT = &H0
Public Const SEE_MASK_NOCLOSEPROCESS = &H40

Public Type SHELLEXECUTEINFO
  cbSize As Long
  fMask As Long
  hwnd As Long
  lpVerb As String
  lpFile As String
  lpParameters As String
  lpDirectory As String
  nShow As Long
  hInstApp As Long
  lpIDList As Long
  lpClass As String
  hkeyClass As Long
  dwHotKey As Long
  hIcon As Long
  hProcess As Long
End Type

'Shell Functions
Public Declare Function ShellExecute Lib "shell32.dll" Alias _
 "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
 ByVal lpFile As String, ByVal lpParameters As String, _
 ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Declare Function ShellExecuteW Lib "shell32" _
 (ByVal hwnd As Long, ByVal lpOperation As Long, _
 ByVal lpFile As Long, ByVal lpParameters As Long, _
 ByVal lpDirectory As Long, ByVal nShowCmd As Long) As Long
Public Declare Function ShellExecuteEx Lib "shell32.dll" Alias "ShellExecuteExA" _
 (pExecInfo As SHELLEXECUTEINFO) As Boolean

...
Рейтинг: 0 / 0
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / VB 6 ShellExecuteEx не возвращает hProcess / 2 сообщений из 2, страница 1 из 1
Целевая тема:
Создать новую тему:
Автор:
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]