Sign in to follow this  
Followers 0
Luigi

kill all process in current user and others accounts...

6 posts in this topic

#1 ·  Posted (edited)

Hi forum!

I write this script to kill a proccess runing in local account, but, I need kill the proccess if is running in another accounts...
Of course, you running this script as #Admin.

If you have a best script, idea, tip, please share it.

Way to use: open calc.exe in local account and another account too...

Br, Detefon

#RequireAdmin
#include <String.au3>
#include <Array.au3>

Local $var = "C:\Windows\System32\calc.exe"
ConsoleWrite(FileExists($var) & @LF)

Local $try = ProcessCloseEx($var)
ConsoleWrite("$try[ " & $try & " ] @error[ " & @error & " ]" & @LF)

Func ProcessCloseEx($sFilePath = 0, $iTry = 20)
    ; sFilePath  must be a full path's file,
    If Not FileExists($sFilePath) Then Return SetError(1, 0, 0)
    Local $aPID = __ProcessList($sFilePath)
    If @error Then Return SetError(@error, 0, 0)
    Local $error

    For $ii = 1 To UBound($aPID, 1) - 1
        ProcessClose($aPID[$ii])
        If @error Then
            Do
                ProcessClose($aPID[$ii])
                $error = @error
                Sleep(250)
                $iTry -= 1
                If Not $iTry Then Return SetError($error, 0, 0)
            Until Not ProcessExists($aPID[$ii])
        EndIf
    Next
    Return True
EndFunc   ;==>ProcessCloseEx

Func __ProcessList($in)
    Local $aRet[1]
    Local $objWMIService = ObjGet('winmgmts:{impersonationLevel=impersonate}!\\' & @ComputerName & '\root\cimv2')
    If Not IsObj($objWMIService) Then Return SetError(5, 0, 0)

    Local $colItems = $objWMIService.ExecQuery("SELECT ExecutablePath,ProcessId FROM Win32_Process WHERE ExecutablePath='" & double_slash($in) & "'", "WQL", 0x30)
    Local $Result = ''
    If IsObj($colItems) Then
        For $objItem In $colItems
            If StringLower($objItem.ExecutablePath) == StringLower($in) Then _ArrayAdd($aRet, $objItem.ProcessId)
        Next
    EndIf
    Return $aRet
EndFunc   ;==>__ProcessList


Func double_slash($sInput = "")
    If Not $sInput Then Return SetError(1, 0, $sInput)
    $sInput = StringReplace($sInput, "/", "*")
    $sInput = StringReplace($sInput, "\", "*")
    Do
        $sInput = StringReplace($sInput, "**", "*")
    Until Not StringInStr($sInput, "**")

    $sInput = StringReplace($sInput, "*", "\\")
    Return $sInput
EndFunc   ;==>double_slash
Edited by Detefon

m(o.O)m

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Probably easier to ProcessGetList (use the first param to limit results), and then loop through with:

_WinAPI_GetProcessFileName

If matches, then close.

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I thought

ProcessClose ( "process" )

is closing a process on all accounts ? Am I wrong ?

Maybe use something like this:

ProcessList ( ["name"] )

And then kill all the processes with ProcessClose. (They are stored in arrays)

Pls don't kill me if it's wrong, I am a beginner :P I guess I am completly wrong lol...

Edited by andrewz

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

@jdelaney, thank you for share, I unknow this command, but I will try.

@andrewz, ProcessClose kill only local account process

I try it now... Open a "calc.exe" in admin account and "calc.exe" in another account... Only the local "calc.exe" was terminated.

ProcessClose("calc.exe")

Br, Detefon

Edited by Detefon

m(o.O)m

Share this post


Link to post
Share on other sites

You have to loop through ProcessClose...It only closes the first PID found.

I thought you just wanted to close a certain process from a certain directory.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

You are write, I need close a process specific.

But all sugestion always welcome.

Br, Detefon


m(o.O)m

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