XP SP2 下代码失效??

bug2002 2004-11-20 08:51:05
小弟最近升级了SP2发现原来在SP1下的代码出问题了!

很简单的一段代码,省略API声明:

Dim pID as long

Private Sub Form_Load()
pID = Shell("c:\windows\NOTEPAD.EXE")
While StillRun(pID)
DoEvents
Wend
End
End Sub

Function StillRun(ByVal ProgramID) As Boolean
Dim lHProgram As Long
Dim lReturn As Long

hProgram = OpenProcess(1, False, ProgramID)
If Not hProgram = 0 Then
StillRun = True
Else
StillRun = False
End If
CloseHandle hProgram
End Function

请问各位高手这是怎么回事啊?

另外,请问已知由GetWindowThreadProcessId 得到的 hProcessID 怎么得到进程的PID?
不胜感激!!!
...全文
94 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
在sp2下使用shell都有写问题的
tztz520 2004-11-21
  • 打赏
  • 举报
回复
'这样看一下.

Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32.dll" (ByVal hProcess As Long, ByRef lpExitCode As Long) As Long
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)

Private Const PROCESS_QUERY_INFORMATION As Long = (&H400)
Private Const STILL_ACTIVE As Long = &H103


Sub ShellWait(FileName As String)
Dim hShell As Long
Dim hProc As Long
Dim lExit As Long

hShell = Shell(FileName, vbNormalFocus)
hProc = OpenProcess(PROCESS_QUERY_INFORMATION, False, hShell)
Do
GetExitCodeProcess hProc, lExit
DoEvents
Loop While lExit = STILL_ACTIVE

End Sub


Private Sub Form_Load()
ShellWait "c:\windows\NOTEPAD.EXE"
End
End Sub
GGL123 2004-11-21
  • 打赏
  • 举报
回复
up
viena 2004-11-20
  • 打赏
  • 举报
回复
up

7,763

社区成员

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

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