找回密码
 加入
搜索
查看: 2505|回复: 10

[AU3基础] 关于ProcessExists检测的求助

    [复制链接]
发表于 2018-1-11 15:13:38 | 显示全部楼层 |阅读模式
$g_szVersion = "notepad.exe"
If ProcessExists($g_szVersion) Then
        MsgBox(0, "", "存在notepad.exe进程")

Else
        MsgBox(0, "", "不存在notepad.exe进程")
EndIf

我想检测当前用户环境中是否有notepad.exe进程,结果如果有其他windows用户运行了notepad.exe,那么会检测到。
请问如何检测当前用户的进程?
谢谢!
发表于 2018-1-11 15:42:16 | 显示全部楼层
当时的需求只需要一个结果,如果需要返回多个结果,自己改善
http://www.autoit3.cn/forum.php?mod=viewthread&tid=51998
发表于 2018-1-11 16:04:30 | 显示全部楼层
回复 1# anythingok


    善用搜索
http://www.autoit3.cn/forum.php? ... C3%BB%A7&page=1
 楼主| 发表于 2018-1-11 20:02:17 | 显示全部楼层
感谢各位的帮助,由于刚学习,很多代码看不懂,能否帮我修改一下,最简单的语句实现就行。
 楼主| 发表于 2018-1-11 20:02:59 | 显示全部楼层
#include <LocalSecurityAuthority.au3>
$sProcess = "notepad.exe"
$iProcessId = ProcessExists($sProcess)
$hProcess = _OpenProcess($iProcessId, $READ_CONTROL)

$sUser = _QueryKernelObjectSecurityOwner($hProcess)

If ($sUser = @UserName) Then
        MsgBox(0, "", "存在notepad.exe进程")
Else
        MsgBox(0, "", "不存在notepad.exe进程")

EndIf

我照着改了一下,好象还差那么一点,在@username位置。
请大神帮看一下。谢谢!
发表于 2018-1-11 21:41:53 | 显示全部楼层
;Au3版本:        3.3.14.2
#include <WinAPIProc.au3>
$aPidList = ProcessList('notepad.exe')
If Not @error Then
        For $i = 1 To $aPidList[0][0]
                $sPid = $aPidList[$i][1]
                $sUser = _GetPidUser($sPid)
                If Not @error Then MsgBox(0,'Pid: ' &$sPid ,'User: ' & $sUser)
        Next
EndIf


;//获取指定PID的用户名
Func _GetPidUser($sPid)
        If Not ProcessExists($sPid) Then Return SetError(-1)
        $aRet = _WinAPI_GetProcessUser($sPid)
        If IsArray($aRet) Then
                Return $aRet[0]
        Else
                Return SetError(-2)
        EndIf
EndFunc   ;==>_GetPidUser
试试这个API的
发表于 2018-1-11 23:03:44 | 显示全部楼层
 楼主| 发表于 2018-2-3 21:29:44 | 显示全部楼层
感谢各位的无私帮助,目前还是没做成。
 楼主| 发表于 2018-2-3 21:33:07 | 显示全部楼层
我想实现检测当前用户是否打开了notepad.exe,如果没打开,就打开notepad.exe,
怎耐这个脚本始终能检测到其它用户运行的notepad.exe,就失效了。

If not ProcessExists("notepad.exe") Then
   
     ShellExecute("C:\\Windows\notepad.exe", "", "" , "",@SW_SHOW)

Else
     MsgBox(0, "例子", "记事本已经在运行.")
EndIf

能否帮我简单改一下,万分感谢!
 楼主| 发表于 2018-2-7 09:45:10 | 显示全部楼层
求指点,求帮助
发表于 2018-2-7 13:57:37 | 显示全部楼层
zghwelcome 不是已经上代码了吗?

#include <WinAPIProc.au3>

If _ProcessUser('notepad.exe') Then
        MsgBox(0, '', '已在运行')
Else
        ShellExecute('C:\Windows\notepad.exe')
EndIf

Func _ProcessUser($ProcessName, $sUser = @UserName)
        Local $aProcess = ProcessList($ProcessName)
        If @error Then Return SetError(1, 0, 0)
        Local $ii, $aUser
        For $ii = 1 To $aProcess[0][0]
                $aUser = _WinAPI_GetProcessUser($aProcess[$ii][1])
                If Not @error And $aUser[0] = $sUser Then Return 1
        Next
        Return 0
EndFunc   ;==>_ProcessUser
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-20 07:48 , Processed in 0.087509 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表