Sign in to follow this  
Followers 0
alaa777

Process using file

6 posts in this topic

if there is a file i want to delete and there is a process using it "so i can`t delete it" how i know the name of the process using that file to close the process and delete that file

Share this post


Link to post
Share on other sites



if there is a file i want to delete and there is a process using it "so i can`t delete it" how i know the name of the process using that file to close the process and delete that file

_WinAPI_FindExecutable()


[u]You can download my projects at:[/u] Pulsar Software

Share this post


Link to post
Share on other sites

_WinAPI_FindExecutable()

thx it worked :o but another problem :D if it returns "c:\pla\plapla\pla\process i need.exe"

i want the "process i need.exe" alone to use ProcessClose()

Share this post


Link to post
Share on other sites

thx it worked :o but another problem :D if it returns "c:\pla\plapla\pla\process i need.exe"

i want the "process i need.exe" alone to use ProcessClose()

Dim $filepath, $szDrive, $szDir, $szFName, $szExt
$filepath = _WinAPI_FindExecutable ($file)
$fileexe = _PathSplit($filepath, $szDrive, $szDir, $szFName, $szExt)
$pid = _ProcessGetPid($fileexe[3] & $fileexe[4])
processclose($pid)

Func _ProcessGetPid($sName) ;borrowed
    If Not ProcessExists($sName) Then
        SetError(1)
        Return ""
    EndIf
    Local $aPList = ProcessList($sName)
    If @error Then Return ""
    Local $aMatches[UBound($aPList) ]
    $aMatches[0] = $aPList[0][0]
    For $i = 1 To $aPList[0][0]
        $aMatches[$i] = $aPList[$i][1]
    Next
    Return $aMatches
EndFunc   ;==>_ProcessGetPid

[u]You can download my projects at:[/u] Pulsar Software

Share this post


Link to post
Share on other sites

Dim $filepath, $szDrive, $szDir, $szFName, $szExt
$filepath = _WinAPI_FindExecutable ($file)
$fileexe = _PathSplit($filepath, $szDrive, $szDir, $szFName, $szExt)
$pid = _ProcessGetPid($fileexe[3] & $fileexe[4])
processclose($pid)

Func _ProcessGetPid($sName) ;borrowed
    If Not ProcessExists($sName) Then
        SetError(1)
        Return ""
    EndIf
    Local $aPList = ProcessList($sName)
    If @error Then Return ""
    Local $aMatches[UBound($aPList) ]
    $aMatches[0] = $aPList[0][0]
    For $i = 1 To $aPList[0][0]
        $aMatches[$i] = $aPList[$i][1]
    Next
    Return $aMatches
EndFunc   ;==>_ProcessGetPid
thx but i made easy one have alook ^^

#Include <WinAPI.au3>
$txt=_WinAPI_FindExecutable($file)
$n=StringInStr($txt,"\",2,-1)
$txt=StringTrimLeft($txt,$n)
ProcessClose($txt)

Share this post


Link to post
Share on other sites

Oh.., heres another way ^^;

Script :

#Include <WinAPI.Au3>
#Include <String.Au3>

Func _FileDelete ($iFile, $iClose = True)
$Process = _WinAPI_FindExecutable ($iFile)
$Process = _StringReverse ($Process)
$Process = StringSplit ($Process, '\')
$Process = _StringReverse ($Process['1'])
If $iClose = True Then 
If ProcessExists ($Process) Then ProcessClose ($Prcoess)
EndIf 
FileDelete ($iFile)
EndFunc

- John


Latest Projects :- New & Improved TCP Chat

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0