注册 登录
编程论坛 VFP论坛

VFP9+win10环境下如何获取操作系统后台已运行软件名称

shschy 发布于 2023-03-23 16:40, 996 次点击
需要获取操作系统后台已运行软件的列表,从中判断某个软件是否被运行,如果没有被运行则由VFP调用对应程序运行。
9 回复
#2
吹水佬2023-03-23 16:49
枚举进程。
#3
shschy2023-03-23 16:50
一个是禁止重复运行,另一个判断是否已被运行。
#4
shschy2023-03-23 16:51
以下是引用吹水佬在2023-3-23 16:49:19的发言:

枚举进程。

如果没有被运行,或因为未知原因退出win10操作系统后台,就需要vfp来强制运行。
#5
csyx2023-03-23 17:39
速度要求不高的话,用 WMI 就可以取出来
#6
csyx2023-03-23 17:53
关键代码就这些,自己再做些修改
程序代码:
Set Nulldisplay To
Create Cursor ttt (name V(50), value V(250))

oWMI = GetObject('winmgmts://')
*!*    cQuery = 'Select * From Win32_Process'
*!*    取这俩属性差不多够用了
cQuery = 'Select Caption,ExecutablePath From Win32_Process'
oRes = oWMI.ExecQuery(cQuery)

Clear
For ii = 0 to oRes.Count - 1
    For each o1 in oRes.ItemIndex(ii).Properties_
        cVal = ''
        If o1.IsArray and !IsNull(o1.Value)
            For each o2 in o1.Value
                cVal = cVal + Transform(o2) + ','
            EndFor
        Else
            cVal = Transform(o1.Value)
        EndIf
        Insert into ttt (name, value) Values (o1.name, cVal)
    EndFor
    Insert into ttt (name) Values ('====================')
EndFor

Locate
Browse nowait

每个进程所有的属性看这里:https://learn.

[此贴子已经被作者于2023-3-23 17:57编辑过]

#7
pvm20002023-03-23 18:34
在Vfp中调用 taskkill ,可获得各进程的详细信息,再用taskkill
杀指定进程。
#8
吹水佬2023-03-23 19:00
以下是引用shschy在2023-3-23 16:50:14的发言:

一个是禁止重复运行,另一个判断是否已被运行。

一个,另一个,都是同一个过程吧。先另判断是否在运行,再是否禁止重复运行。
具体是什么情况? 处理本进程与外部进程是不同的。
#9
sam_jiang2023-03-23 20:03
给你段代码,你看看用不用得上。。。
程序代码:

*-- VFP Code
#Define GW_NEXT 2
#define GW_CHILD 5
Declare Integer GetActiveWindow In user32
Declare Integer GetWindow In win32api Integer HWnd, Integer wFlag
Declare Integer GetWindowTextA In win32api Integer hwnd, String @ctitle, Integer ntitle
Declare Integer SetForegroundWindow In Win32api Integer
DECLARE inte IsChild IN WIN32API integer Hwndparent,integer Hwnd
Declare inte FindWindowEx IN win32api inte hWnd1,inte hWnd2, string lpsz1, string lpsz2
Declare Integer GetWindowText In win32api Integer hand, String @ctitle, Integer ntitle

clea
*hcurrent=findwindowex(_vfp.hwnd,0,null,null)
hcurrent=findwindowex(0,0,null,null)
*?hcurrent
*hCurrent=GetActiveWindow()    &&从当前活动窗口开始
*lnhCurrent=hCurrent
*SetForegroundWindow(_vfp.HWnd)
*SetForegroundWindow(_Screen.HWnd)  &&或Thisform.HWnd
*SetForegroundWindow(hCurrent)        && vfp8 以下没有 HWnd
*lcWinLists=""
Create Cursor t1 (WindowHWnd I,WindowTitle C(254))
Do While hCurrent!=0
    lcWinTitle=Space(255)
    lnlength=GetWindowTextA(hCurrent,@lcWinTitle,Len(lcWinTitle))
    lcwintitle=SUBSTR(lcwintitle,1,lnlength)
    *lcWinTitle=Iif(lnlength>0,Strtran(Trim(lcWinTitle),Chr(0),""),"")
    Insert Into t1 Values (hCurrent,lcWinTitle)
    *hCurrent=findwindowex(_vfp.hwnd,hcurrent,null,null)   &&得到下一个窗口句柄
    hCurrent=findwindowex(0,hcurrent,null,null)   &&得到下一个窗口句柄
    *?ischild(_vfp.hWnd,hcurrent)
    *?hcurrent   
Enddo
*SetForegroundWindow(lnhCurrent)
Select t1
*Locate
Browse
*Clear Dlls
#10
schtg2023-03-24 05:41
6楼、9楼的大侠,谢谢!
1