本帖最后由 lixiaolong 于 2011-3-10 16:33 编辑
回复 3# leon460
看看这个可以不?按xyold1说的方法写了一个.
只能检查一个进程,有些程序无法获取(比如SciTE).
$a = WhatProcessOpenFile("1.txt")
If Not @error Then
MsgBox(0, '文件名 - ' & $a[0], $a[1])
Else
MsgBox(16, '文件名 - ' & $a[0], '指定的文件未打开!')
EndIf
Func WhatProcessOpenFile($File)
Local $ProcessName[2], $WinName
Local $WinList = WinList()
Local $ProcessList = ProcessList()
Local $StringLen = StringLen($File)
For $i = 1 To $WinList[0][0]
If $WinList[$i][0] <> '' Then ConsoleWrite($WinList[$i][0] & @CRLF)
If StringInStr($WinList[$i][0], $File) <> 0 Then
$WinName = StringRegExpReplace($WinList[$i][0], '.+(?=\\' & $File & ')', '')
If StringLeft($WinName, $StringLen) = $File Or _
StringLeft($WinName, $StringLen) = '\' & _
StringMid($File, 1, $StringLen - 1) Then
$ProcessList = ProcessList()
For $s = 1 To $ProcessList[0][0]
If $ProcessList[$s][1] = WinGetProcess _
($WinList[$i][0]) Then ExitLoop
Next
$ProcessName[1] = $ProcessList[$s][0]
SetError(0)
ExitLoop
EndIf
Else
$ProcessName[1] = ''
SetError(1)
EndIf
Next
$ProcessName[0] = $File
Return $ProcessName
EndFunc ;==>WhatProcessOpenFile
|