关于进程问题

jqfeng75 2003-09-03 03:52:26
请问如何取得指定应用的进程句柄(比如我打开了EXCEL.EXE,我要取他的进程句柄),谢谢!
...全文
19 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
sxy73 2004-02-17
  • 打赏
  • 举报
回复
你好!看见你关于进程方面的信息,但下面的用户对象及数据窗口对象
是如何定义的,请赐教!
nvo_process 及d_process


sxy73@sina.com
killerdanny 2003-09-03
  • 打赏
  • 举报
回复
type lb_1 from listbox within w_processes
boolean visible = false
integer x = 1691
integer y = 32
integer width = 736
integer height = 504
integer taborder = 40
integer textsize = -9
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
borderstyle borderstyle = stylelowered!
end type

type cb_2 from commandbutton within w_processes
integer x = 727
integer y = 1360
integer width = 343
integer height = 104
integer taborder = 30
integer textsize = -9
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
string text = "结束进程"
end type

event clicked;//invo_process.il_processID=il_current_processid
uint lui_exitcode
//ExitProcess(0)
ulong dwDesiredAccess
ulong bInheritHandle
ulong dwProcessId
ulong lui_exitcode1
//messagebox("",il_current_processid)
if il_current_processid < 0 then return
lui_exitcode1=OpenProcess(dwDesiredAccess,bInheritHandle,il_current_processid)

messagebox("",lui_exitcode1)
if TerminateProcess(lui_exitcode1,lui_exitcode) then
messagebox("", "杀掉进程成功")
dw_1.reset()
cb_1.triggerevent(clicked!)
else
messagebox("", "杀掉进程失败")
end if
//messagebox(string(invo_process.il_processID),string(il_current_processid))
//if invo_process.uf_DestroyProcess() then
// messagebox("", "Killed !")
//else
// messagebox("", "error!")
//end if
end event
type cb_1 from commandbutton within w_processes
integer x = 375
integer y = 1360
integer width = 343
integer height = 104
integer taborder = 20
integer textsize = -9
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
string text = "进程列表"
end type

event clicked;//messagebox("",string(lul_th32ProcessID))
ulong lul_hSnapshot, lul_th32ProcessID,lu_ProcessID

invo_process = CREATE nvo_process
invo_process.il_maxtime = 30
invo_process.ib_destroy_after_wait = true
invo_process.ii_windowstate = 1

PROCESSENTRY32 lpe_processentry
SetNull (lul_th32ProcessID)
lul_hSnapshot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, lul_th32ProcessID)
long i
lb_1.Reset()
lb_processes.reset()
DW_1.RESET()
if lul_hSnapshot > 0 then

lpe_processentry.dwSize = 296
if Process32First (lul_hSnapshot, lpe_processentry) then
do
lb_processes.AddItem (lpe_processentry.szExeFile)
//lu_ProcessID=GetCurrentProcessId()
lb_1.AddItem(string(lpe_processentry.th32ProcessID))
//il_processid[i]=lpe_processentry.th32ProcessID
//i++
I=DW_1.INSERTROW(0)
DW_1.OBJECT.process_exename[I]=lpe_processentry.szExeFile
DW_1.OBJECT.process_exEID[I]=lpe_processentry.th32ProcessID
DW_1.OBJECT.dwsize[I]=lpe_processentry.dwsize
loop while Process32Next (lul_hSnapshot, lpe_processentry)
end if

CloseHandle (lul_hSnapshot)
end if
killerdanny 2003-09-03
  • 打赏
  • 举报
回复
event open;DW_1.SETTRANSOBJECT(SQLCA)
DW_1.RESET()
CB_1.TRIGGEREVENT(CLICKED!)
end event
type cb_4 from commandbutton within w_processes
integer x = 1074
integer y = 1360
integer width = 594
integer height = 104
integer taborder = 40
integer textsize = -9
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
string text = "查看当前进程是否运行"
end type

event clicked;if invo_process.uf_isrunning(il_current_processid,is_exename) then
messagebox("","所选进程正在运行")
else
messagebox("","所选进程没运行")
end if

end event
type sle_1 from singlelineedit within w_processes
integer x = 32
integer y = 1236
integer width = 2277
integer height = 104
integer taborder = 30
integer textsize = -9
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
borderstyle borderstyle = stylelowered!
end type

type cb_3 from commandbutton within w_processes
integer x = 27
integer y = 1360
integer width = 343
integer height = 104
integer taborder = 20
integer textsize = -9
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
string text = "创建进程"
end type

event clicked;if sle_1.text = "" then return
if invo_process.uf_createprocess(sle_1.text) then
DW_1.RESET()
CB_1.TRIGGEREVENT(CLICKED!)
MESSAGEBOX("","进程创建成功")
else
MESSAGEBOX("","进程创建失败")
end if
end event
type dw_1 from datawindow within w_processes
integer x = 9
integer y = 8
integer width = 2304
integer height = 1192
integer taborder = 50
string title = "none"
string dataobject = "d_process"
boolean hscrollbar = true
boolean vscrollbar = true
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

event clicked;if row >0 then
il_current_processid=this.object.process_exeid[row]
IS_EXENAME =this.object.process_exename[row]
//messagebox("",il_current_processid)
end if
end event
killerdanny 2003-09-03
  • 打赏
  • 举报
回复
forward
global type w_processes from window
end type
type cb_4 from commandbutton within w_processes
end type
type sle_1 from singlelineedit within w_processes
end type
type cb_3 from commandbutton within w_processes
end type
type dw_1 from datawindow within w_processes
end type
type lb_1 from listbox within w_processes
end type
type cb_2 from commandbutton within w_processes
end type
type cb_1 from commandbutton within w_processes
end type
type lb_processes from listbox within w_processes
end type
type cb_ok from commandbutton within w_processes
end type
type processentry32 from structure within w_processes
end type
end forward

type PROCESSENTRY32 from structure
ulong dwSize
ulong cntUsage
ulong th32ProcessID
ulong th32DefaultHeapID
ulong th32ModuleID
ulong cntThreads
ulong th32ParentProcessID
long pcPriClassBase
ulong dwFlags
character szExeFile[260]
end type

global type w_processes from window
integer x = 1056
integer y = 484
integer width = 2546
integer height = 1800
boolean titlebar = true
string title = "进程管理"
boolean controlmenu = true
boolean minbox = true
boolean maxbox = true
boolean resizable = true
long backcolor = 78682240
cb_4 cb_4
sle_1 sle_1
cb_3 cb_3
dw_1 dw_1
lb_1 lb_1
cb_2 cb_2
cb_1 cb_1
lb_processes lb_processes
cb_ok cb_ok
end type
global w_processes w_processes

type prototypes
Function ulong CreateToolhelp32Snapshot (ulong dwFlags, ulong th32ProcessID) Library "KERNEL32.DLL"
Function boolean Process32First (ulong hSnapshot, ref PROCESSENTRY32 lppe) Library "KERNEL32.DLL"
Function boolean Process32Next (ulong hSnapshot, ref PROCESSENTRY32 lppe) Library "KERNEL32.DLL"
Function boolean CloseHandle (ref ulong hObject) Library "KERNEL32.DLL"
FUNCTION boolean TerminateProcess (ulong hProcess, uint uExitCode) LIBRARY "KERNEL32.DLL"
FUNCTION ulong GetCurrentProcessId() LIBRARY "kernel32.dll"
Subroutine ExitProcess(ulong uExitCode) LIBRARY "kernel32.dll"
FUNCTION boolean GetExitCodeProcess (ulong hProcess, Ref uint lpExitCode) LIBRARY "KERNEL32.DLL"
FUNCTION ulong GetCurrentProcess() LIBRARY "kernel32.dll"
FUNCTION ulong OpenProcess(ulong dwDesiredAccess,ulong bInheritHandle,ulong dwProcessId) LIBRARY "kernel32.dll"

end prototypes
type variables
nvo_process invo_process
ulong il_processid[]
ulong il_current_processid
long il_index
STRING IS_EXENAME
private:
constant ulong TH32CS_SNAPHEAPLIST = 1 //0x00000001
constant ulong TH32CS_SNAPPROCESS = 2 //0x00000002
constant ulong TH32CS_SNAPTHREAD = 4 //0x00000004
constant ulong TH32CS_SNAPMODULE = 8 //0x00000008
constant ulong TH32CS_SNAPALL = TH32CS_SNAPHEAPLIST + TH32CS_SNAPPROCESS + TH32CS_SNAPTHREAD + TH32CS_SNAPMODULE
constant ulong TH32CS_INHERIT = 2147483648 //0x80000000

end variables
on w_processes.create
this.cb_4=create cb_4
this.sle_1=create sle_1
this.cb_3=create cb_3
this.dw_1=create dw_1
this.lb_1=create lb_1
this.cb_2=create cb_2
this.cb_1=create cb_1
this.lb_processes=create lb_processes
this.cb_ok=create cb_ok
this.Control[]={this.cb_4,&
this.sle_1,&
this.cb_3,&
this.dw_1,&
this.lb_1,&
this.cb_2,&
this.cb_1,&
this.lb_processes,&
this.cb_ok}
end on

on w_processes.destroy
destroy(this.cb_4)
destroy(this.sle_1)
destroy(this.cb_3)
destroy(this.dw_1)
destroy(this.lb_1)
destroy(this.cb_2)
destroy(this.cb_1)
destroy(this.lb_processes)
destroy(this.cb_ok)
end on
jqfeng75 2003-09-03
  • 打赏
  • 举报
回复
我如何用FINDWINDOW获得EXCEL.EXE的句柄,两个REF参数如何设置!
Jonea 2003-09-03
  • 打赏
  • 举报
回复
Function long FindWindow (ref string lpClassName, ref string lpWindowName)Library "user32"
Function long GetWindowThreadProcessId (ref long hwnd,ref long lpdwProcessId)Library "user32"

FindWindow 返回符合指定的类名( ClassName )和窗口名( WindowTitle )的窗口句柄
我们把 FindWindow 函数中得到的句柄作为参数,来获得进程名柄lpdwProcessID

396

社区成员

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

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