Jump to content

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


Luigi
 Share

Recommended Posts

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

Visit my repository

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

@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

Visit my repository

Link to comment
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.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...