A为我写的程序,B为现成程序,A用SHELL打开B,当关B时,如何让A知道?(返回)

qivictor 2003-10-15 03:37:14
可有Sample code?
...全文
80 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
qivictor 2003-10-20
  • 打赏
  • 举报
回复
自己顶一下

看还有没有别的方法
sdmltyj 2003-10-18
  • 打赏
  • 举报
回复
up
efei4000 2003-10-18
  • 打赏
  • 举报
回复
xwzxwz(xwz)
子进程,这个方法最好,耗资源最少!!!
用timer当然也可以!
hhjjhjhj 2003-10-17
  • 打赏
  • 举报
回复
Shell返回进程ID,跟据这个ID得到句柄,监控拥有这个句柄的窗体是否存在
qivictor 2003-10-17
  • 打赏
  • 举报
回复
to:siyou
呵呵,我要监控的正是程序B的窗体名。。。。。。。。。因为B的窗体名是有可能会变的,嘻嘻

FINDWINDOW我已经试过,但中间还是有些小问题没解决

我很郁闷。。。。。。。

再次请看贴的兄弟姐妹帮我顶一下。。。。。。。。。。。。。
LVOLCANO 2003-10-17
  • 打赏
  • 举报
回复
up
CTBOK 2003-10-17
  • 打赏
  • 举报
回复
首先TIMER是一定要有的,其次是用 FINDWINDOW的API,监测是否有B这个进程存在,其实也峭什么难的,B进程的窗体名字一定是固定的吧?所以FINDWINDOW这个API可以实现
xwzxwz 2003-10-16
  • 打赏
  • 举报
回复
忘了,用timer循环调用
qivictor 2003-10-16
  • 打赏
  • 举报
回复
to:virtualdesktop
我所说的B程序是要随时可能关闭的,所以还是需要一个类似TIMER的东东进行监控的

to: xwzxwz
这几天都没睡好,现在看代码有点子小累(哪叫你贴那么多呀,呵呵,开个玩笑,谢谢)

你们的思路我大概明白点,你们都是从进程着手突破的,我也会再试试,我在这再顶一下看看还有没有兄弟帮着出出主意

有看这贴子的兄弟(姐妹)帮着顶顶呀,兄弟在此表示感谢!
qivictor 2003-10-16
  • 打赏
  • 举报
回复
我因为用A程序中的TIMER侦测B程序中的一个窗体上的变量,所以要用到TIMER,你们说的方法我回家去试试,现在要下班了,哈哈,谢谢各位兄弟,大家多多交流呀,我有什么主意再和大家说
谢谢xwzxwz,virtualdesktop,
VirtualDesktop 2003-10-15
  • 打赏
  • 举报
回复
上面的连TIMER都不用~
VirtualDesktop 2003-10-15
  • 打赏
  • 举报
回复
这个好办:

Option Explicit


' Shows how to shell to another program, and wait until it finishes
' before continuing.

Private Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long

Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long


Private Const INFINITE = -1&
Private Const SYNCHRONIZE = &H100000

Private Sub Command1_Click()
Dim iTask As Long, ret As Long, pHandle As Long
iTask = Shell("notepad.exe", vbNormalFocus)
pHandle = OpenProcess(SYNCHRONIZE, False, iTask)
ret = WaitForSingleObject(pHandle, INFINITE)
ret = CloseHandle(pHandle)
MsgBox "程序运行完成!"
End Sub
xwzxwz 2003-10-15
  • 打赏
  • 举报
回复
注:win98的
我就是小白
大家不要骂了
呵呵
我也在想这方面的问题
交流一下:xwz_xwz.student@sina.com
xwzxwz 2003-10-15
  • 打赏
  • 举报
回复

Dim tProcInfo As PROCESS_INFORMATION, lRetVal As Long, lSuccess As Long
Dim tStartupInf As STARTUPINFO
Dim tSecurAttrib As SECURITY_ATTRIBUTES
Dim hSnapShot As Long, uProcess As PROCESSENTRY32
Const SW_HIDE = 0, SW_NORMAL = 1
Const NORMAL_PRIORITY_CLASS = &H20&
Const TH32CS_SNAPHEAPLIST = &H1
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPTHREAD = &H4
Const TH32CS_SNAPMODULE = &H8
Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
Const TH32CS_INHERIT = &H80000000
'---------------------------------------------------------------------------

Private Declare Function CreateProcessA Lib "kernel32" _
(ByVal lpApplicationName As Long, ByVal lpCommandLine As _
String, lpProcessAttributes As Any, lpThreadAttributes As _
Any, ByVal bInheritHandles As Long, ByVal dwCreationFlags As _
Long, ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As _
Long, lpStartupInfo As Any, lpProcessInformation As Any) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" _
(ByVal lFlags As Long, ByVal lProcessID As Long) As Long

Private Declare Function Process32First Lib "kernel32" _
(ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long

Private Declare Function Process32Next Lib "kernel32" _
(ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
'--------------------------------------------------------------------------------------------


Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type

Private 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 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 Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * MAX_PATH
End Type



tSecurAttrib.nLength = Len(tSecurAttrib)
tSecurAttrib.bInheritHandle = 1&
tSecurAttrib.lpSecurityDescriptor = 0&
CreatePipe(lhwndReadPipe, lhwndWritePipe, tSecurAttrib, 0)
tStartupInf.cb = Len(tStartupInf)
tStartupInf.dwFlags = STARTF_USESTDHANDLES Or STARTF_USESHOWWINDOW
tStartupInf.hStdOutput = lhwndWritePipe
tStartupInf.wShowWindow = SW_HIDE
CreateProcessA(0&, sCommandLine, tSecurAttrib, tSecurAttrib, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, tStartupInf, tProcInfo)
Dim r, n, i
'============================================================================================================
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&)
uProcess.dwSize = Len(uProcess)
r = Process32First(hSnapShot, uProcess)
Do While r
n = LCase(Left$(uProcess.szExeFile, IIf(InStr(1, uProcess.szExeFile, Chr$(0)) > 0, InStr(1, uProcess.szExeFile, Chr$(0)) - 1, 0)))
For i = Len(n) To 1 Step -1
If Mid$(n, i, 1) = "\" Then n = Mid$(n, i + 1, Len(n) - i)
Next i
If n = "uharc.exe" Then
CloseHandle hSnapShot
Exit Function
End If
'Retrieve information about the next process recorded in our system snapshot
r = Process32Next(hSnapShot, uProcess)
Loop
'close our snapshot handle
CloseHandle hSnapShot
GoTo Err:
'============================================================================================================


Exit Function
Err:
'Close handles
Call CloseHandle(tProcInfo.hProcess)
Call CloseHandle(tProcInfo.hThread)
qivictor 2003-10-15
  • 打赏
  • 举报
回复
A在打开B后并没有关闭掉,而是在使用TIMER在不停的侦测B程序的状态,所以我要获得B是否仍在运行的状态来对A进行操作,请哪位哥们(姐们也行)帮个忙啦

1,485

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧