Egg Posted December 31, 2019 Share Posted December 31, 2019 Hi! My script below is supposed to kill all instances of program.exe running (I have a desktop .exe that users click to run it). The program hogs a serial port and people forget to log out, causing issues for the next user who tries to use the program. However, even when I run it while logged in as the local administrator account, it ONLY closes the logged-in user's instance and no one else's. This is on Windows 10 Professional (latest service pack, etc). Any ideas? $struusername = "administrator" $strpassword = "password" $strdomain = @ComputerName $systemdrive = EnvGet("SYSTEMDRIVE") $process = "program.exe" $processname = "ProgramName" $return = MsgBox(4, "Stop " & $processname, "Would you like to stop " & $processname & " ?") If $return == 6 Then RunAsWait($struusername, $strdomain, $strpassword, 0, "cmd.exe /c taskkill /F /IM " & $process) EndIf Link to comment Share on other sites More sharing options...
iamtheky Posted December 31, 2019 Share Posted December 31, 2019 You are running cmd.exe as admin, but taskkill is still running in the context of the logged in user? Things to try to test that: Specify the username and password in your taskkill command instead of the runas for cmd.exe (https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/taskkill) Or #requireadmin might get you there as well, if changing the user context of the script changes the behavior of taskkill, thats a blind stab though. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Nine Posted December 31, 2019 Share Posted December 31, 2019 You do not need to run cmd.exe /c. You can run TaskKill.exe directly. Tested on Win7. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Subz Posted January 1, 2020 Share Posted January 1, 2020 (edited) You can use something like the following function to list the users for a particular process and then kill the appropriate process id, expandcollapse popup#RequireAdmin #include <Array.au3> Global $g_oComError = ObjEvent("AutoIt.Error","MyErrFunc") ;~ Kill all $g_sProcessName that DON'T belong to $g_ProcessUser ;~ Use: ScriptName.exe Username to define the username you don't want closed (default @Username) Global $g_ProcessUser = $CmdLine[0] > 0 ? $CmdLineRaw : @UserName Global $g_sProcessName = "Scite.exe" Global $g_aProcessUsers = _GetProcessOwners("scite.exe") _ArrayDisplay($g_aProcessUsers) For $i = UBound($g_aProcessUsers) - 1 To 0 Step - 1 If $g_aProcessUsers[$i][1] <> $g_ProcessUser Then MsgBox(4096, "Process Info", "ProcessClose(" & $g_aProcessUsers[$i][2] & ") or TaskKill the following: " & @CRLF & _ "Process Name: " & $g_aProcessUsers[$i][0] & @CRLF & _ "Process UserName: " & $g_aProcessUsers[$i][1] & @CRLF & _ "Process Id " & $g_aProcessUsers[$i][2]) EndIf Next Func _GetProcessOwners($_sProcessName, $_sComputerName = ".") Local $aProcessUsers[0][3] Local $oWMIService = ObjGet("winmgmts://" & $_sComputerName & "/root/cimv2") Local $oProcesses = $oWMIService.ExecQuery("Select * from Win32_Process Where Name ='" & $_sProcessName & "'") For $oProcess In $oProcesses If $oProcess.Name = $_sProcessName Then ReDim $aProcessUsers[UBound($aProcessUsers) + 1][3] $aProcessUsers[UBound($aProcessUsers) - 1][0] = $oProcess.Name $aProcessUsers[UBound($aProcessUsers) - 1][1] = Null $oProcess.GetOwner($aProcessUsers[UBound($aProcessUsers) - 1][1]) $aProcessUsers[UBound($aProcessUsers) - 1][2] = $oProcess.ProcessId EndIf Next Return $aProcessUsers EndFunc Func _ObjErrorFunc() Local $iHexNumber = Hex($g_oComError.number,8) Msgbox(4096, "","We intercepted a COM Error !" & @CRLF & _ "Number is: " & $iHexNumber & @CRLF & _ "WinDescription is: " & $g_oComError.windescription & @CRLF & _ "Source is: " & $g_oComError.source & @CRLF & _ "Script Line is: " & $g_oComError.scriptline) Return "" Endfunc Edited January 2, 2020 by Subz Link to comment Share on other sites More sharing options...
Egg Posted January 2, 2020 Author Share Posted January 2, 2020 Thank-you! The first suggestions made no difference, so I'm going to try Subz's and will let you know how it turns out. Link to comment Share on other sites More sharing options...
Egg Posted January 2, 2020 Author Share Posted January 2, 2020 Ahhh, I was hoping Subz's was a little "works out of the box" haha and I'd just plop in my process names. It's little too advanced for me, I'm afraid -- I have no idea what the array.au3 and cmdline.au3 files are supposed to contain, so it errors out immediately. Link to comment Share on other sites More sharing options...
Nine Posted January 2, 2020 Share Posted January 2, 2020 On 12/31/2019 at 9:08 AM, Egg said: However, even when I run it while logged in as the local administrator account, it ONLY closes the logged-in user's instance and no one else's. Maybe just create a task scheduler event when user logged off that kills the process ? Like always if you make a runable script with a specific path of actions so we can replicate the issue. You would get more solution.... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Subz Posted January 2, 2020 Share Posted January 2, 2020 Sorry just remove the following line, I wrote it over a different script and forgot to remove that line, the #include <Array.au3> is only required for _ArrayDisplay() #include <CmdLine.au3> 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