Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

How to kill a process?



  • Please log in to reply
17 replies to this topic
vyserage
  • Members
  • 16 posts
  • Last active: Oct 07 2014 07:15 PM
  • Joined: 18 Sep 2014
Could anybody help me out by writeing up the code required to kill the process "WerFault.exe*32 it would be greatly appreciated!

bruno
  • Members
  • 635 posts
  • Last active: Nov 04 2015 02:26 PM
  • Joined: 07 Mar 2011

from the sister forum: ;)

; http://ahkscript.org/boards/viewtopic.php?f=5&t=3443

#SingleInstance force
#NoEnv
SetTitleMatchMode 2
SetWorkingDir %A_ScriptDir%

Gui, -AlwaysOnTop +Caption -ToolWindow +Border -Resize
Gui, Add, listview,x10 r30 w300 vLst gLst +AltSubmit, ProcessName|ProcessID
gosub, LoadProcessList
Gui, 1:Show, Autosize, ProcessList
return

GuiEscape:
GuiClose:
  ExitApp
return

Lst:
    if (A_GuiEvent = "DoubleClick" ) {
        LV_GetText(xNam,A_EventInfo,1)
        LV_GetText(xPid,A_EventInfo,2)
        msgbox % "Pid`t" xpid  "`nName`t" xNam
    }
    if (A_GuiEvent = "RightClick" ) {
        LV_GetText(xNam,A_EventInfo,1)
        LV_GetText(xPid,A_EventInfo,2)
        MsgBox, 36, , Pid : %xPid%`nName :  %xNam%`n`nEnd process?
        ifMsgBox,Yes
        {
            if (SafeProcessKill(xPid))
{
                MsgBox, 64, , Process Successfully ended.
Reload ; Added
}
            else
                MsgBox, 48, , Failure : Could not end the process
        }
    }
return

SafeProcessKill(p) {
    WinClose,ahk_pid %p%
    WinWaitClose,ahk_pid %p%,,1
    if (ErrorLevel) ; Force kill
    {
        MsgBox, 36, , The process refuses to close.`nForce kill?
        ifMsgBox,No
            return 0
        Process,Close,%p%
        return ErrorLevel
    }
    return 1
}

LoadProcessList:
 GuiControl, -Redraw, Lst
  LV_Delete()
  for process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process")
  {    
    lv_add("", Process.Name, process.processID)
  }
  LV_ModifyCol()
  LV_ModifyCol(2,"50 Integer")
  GuiControl, +Redraw, Lst
return


vyserage
  • Members
  • 16 posts
  • Last active: Oct 07 2014 07:15 PM
  • Joined: 18 Sep 2014
i can make absolutely no sense of that O_o i figured it would only be a couple lines of code and thats it :p No clue what to do with that, i looked through it but didnt even see a kill process of WerFault.exe*32 Basically im trying to make it loop check every 60 seconds to close WerFault.exe*32 if it exists. Thats prety much it :p

kon
  • Members
  • 1652 posts
  • Last active:
  • Joined: 04 Mar 2013

Process, Close, PID-or-Name-goes-here
 
Process, Exist, PID-or-Name-goes-here



vyserage
  • Members
  • 16 posts
  • Last active: Oct 07 2014 07:15 PM
  • Joined: 18 Sep 2014
This is what im using now:
 
Loop{
Process, Close, wow.exe*32
Sleep, 60000
}
 
But it doesnt work on *32 processes :(  Which is what i need it to work on. It kill's plain process names just fine, plain being the ones without *32.
Not sure what else to try :( Anybody have any ideas?


bruno
  • Members
  • 635 posts
  • Last active: Nov 04 2015 02:26 PM
  • Joined: 07 Mar 2011

u need PID. diligently dissect the code ( http://ahkscript.org....php?f=5&t=3443 ). ;)



kon
  • Members
  • 1652 posts
  • Last active:
  • Joined: 04 Mar 2013
But it doesnt work on *32 processes :(  Which is what i need it to work on. It kill's plain process names just fine, plain being the ones without *32.
Not sure what else to try :( Anybody have any ideas?

I can think of two things, but I'm guessing. 1) you don't have permission to close the process. You could try opening Windows Task Manager > Services > Open Services. Then change the service to either Manual of Disabled. OR 2) You have a virus of some kind, and you should try a full virus scan with Windows booted into safe mode.

But in either of those cases, this isn't really an issue with AHK.



girlgamer
  • Moderators
  • 3263 posts
  • Last active: Feb 01 2015 09:49 AM
  • Joined: 04 Jun 2010
If this doesn't work it may be because you're not running with admin privilege.
SetTitleMatchMode, 2
 
KillProcessTimer:
  Process, Close, WerFault.exe
  SetTimer, KillProcessTimer, -10000
  return

esc::Exitapp
BTW this routine with the correct name (leaving out the *32) can close every *32 process in my machine
even if the process doesn't post a pid

The universe is a wondrous place! The faster you create unbreakable code, the faster the universe creates people that can break it. All scripting follows the rule Rule Of Twos -- 1) Good, 2) Fast 3) Cheap -- pick any Two.
I guarantee absolutely nothing about any code I provide except that it works in my machine. ●
MMO Fighter   KeyLooperDemo   Key Spammer   TinyClickRecorder  GGs Password Generator.ahk
For the newest version of AutoHotkey and some killer scripts go here.
Rock-on%20kitten.gif


vyserage
  • Members
  • 16 posts
  • Last active: Oct 07 2014 07:15 PM
  • Joined: 18 Sep 2014

Girlgamer yours did the job! Thanks a lot! However i still have 1 last problem that needs to be solved!

This is how i have the code:

 

Loop{
SetTitleMatchMode, 2


KillProcessTimer:
  Process, Close, WerFault.exe
  SetTimer, KillProcessTimer, -10000
}
 
The issue im having is i think its CONSTANTLY running, which is eating up a good 20 - 40% cpu. How do i make it only run once every 30 seconds? I tried putting a sleep 30000 but that causes an error about it requireing a "return" before " } "  which then just closes after its done sleeping :(


girlgamer
  • Moderators
  • 3263 posts
  • Last active: Feb 01 2015 09:49 AM
  • Joined: 04 Jun 2010
why the heck do you have a loop there? it's a timer. it runs continuously and kills the process every ten
seconds if it exists. The original code also contained an esc::exitapp that will end the script. You don't
need or want the loop. To change the timing to every 30 seconds change the -10000 to -30000 and remove anything
related to the loop. See the code below.
SetTitleMatchMode, 2
 
KillProcessTimer:
  Process, Close, WerFault.exe
  SetTimer, KillProcessTimer, -30000
  return

esc::Exitapp
Put a link to this script on your desktop when you need it you can just click on the link.
when you want to stop the script press esc. its just that easy. The trick with programming
is trying to understand what the code is actually doing and not just assuming you know. Use
the help file to research each line in the code to see what it does.

The universe is a wondrous place! The faster you create unbreakable code, the faster the universe creates people that can break it. All scripting follows the rule Rule Of Twos -- 1) Good, 2) Fast 3) Cheap -- pick any Two.
I guarantee absolutely nothing about any code I provide except that it works in my machine. ●
MMO Fighter   KeyLooperDemo   Key Spammer   TinyClickRecorder  GGs Password Generator.ahk
For the newest version of AutoHotkey and some killer scripts go here.
Rock-on%20kitten.gif


kon
  • Members
  • 1652 posts
  • Last active:
  • Joined: 04 Mar 2013

Closing the process is probably just a band-aid solution to the real underlying problem. You are far better off to try and fix the source of the errors that Windows is reporting. For example, read the Answer here. And read more here.



vyserage
  • Members
  • 16 posts
  • Last active: Oct 07 2014 07:15 PM
  • Joined: 18 Sep 2014

I have a loop because each time i start it, it instantly closes. 

 

I removed the loop but it now just runs once and instantly closes again.

 

@Kon - The crashes are caused by another program that links to the 2nd program that crashes sometimes if the 1st program crashes. Its completely unavoidable unless the dev's fix it which is unlikely.



kon
  • Members
  • 1652 posts
  • Last active:
  • Joined: 04 Mar 2013

The crashes are caused by another program that links to the 2nd program that crashes sometimes if the 1st program crashes. Its completely unavoidable unless the dev's fix it which is unlikely.

Can't you just disable error reporting?



vyserage
  • Members
  • 16 posts
  • Last active: Oct 07 2014 07:15 PM
  • Joined: 18 Sep 2014

Can't you just disable error reporting?

lol really?? Where is that at? The thought never even occured to me.

 

edit: Looking it up now on google and am following the steps necessary, we'l see if this works :)



vyserage
  • Members
  • 16 posts
  • Last active: Oct 07 2014 07:15 PM
  • Joined: 18 Sep 2014

Haha well that was short lived, the error box for "lkjasdjf has stopped working" and only option of "Close" still pops up, and my game will not close until i click the close button, so looks like ill still need the macro.