Luigi Posted December 9, 2014 Share Posted December 9, 2014 (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 expandcollapse popup#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 December 9, 2014 by Detefon Visit my repository Link to comment Share on other sites More sharing options...
jdelaney Posted December 9, 2014 Share Posted December 9, 2014 (edited) Probably easier to ProcessGetList (use the first param to limit results), and then loop through with: _WinAPI_GetProcessFileName If matches, then close. Edited December 9, 2014 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 More sharing options...
andrewz Posted December 10, 2014 Share Posted December 10, 2014 (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 I guess I am completly wrong lol... Edited December 10, 2014 by andrewz Link to comment Share on other sites More sharing options...
Luigi Posted December 10, 2014 Author Share Posted December 10, 2014 (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 December 10, 2014 by Detefon Visit my repository Link to comment Share on other sites More sharing options...
jdelaney Posted December 10, 2014 Share Posted December 10, 2014 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 More sharing options...
Luigi Posted December 10, 2014 Author Share Posted December 10, 2014 You are write, I need close a process specific. But all sugestion always welcome. Br, Detefon Visit my repository Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now