AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Close all programs running from...
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Laszlo



Joined: 14 Feb 2005
Posts: 4517
Location: Boulder, CO

PostPosted: Thu Feb 23, 2006 3:32 pm    Post subject: Reply with quote

Thanks! PSKill ended the process with a single call.
Back to top
View user's profile Send private message
corrupt



Joined: 29 Dec 2004
Posts: 2446

PostPosted: Fri Feb 24, 2006 5:30 am    Post subject: Reply with quote

I have used that utility in the past also for stubborn to kill applications. It would be interesting to find out the method(s) they use to kill tasks...
Back to top
View user's profile Send private message Visit poster's website
corrupt



Joined: 29 Dec 2004
Posts: 2446

PostPosted: Fri Feb 24, 2006 10:39 am    Post subject: Reply with quote

@Laszlo
Now that I'd like to find a task I can't kill easily I can't seem to locate one at the moment Laughing ... Does this work to kill the app you were having trouble with (I'm guessing not but ...)?

Code:

; code by Serenity, shimanov
; pieced together and modified by corrupt

if A_OSVersion in WIN_95,WIN_98,WIN_ME
{
  MsgBox, 16, Error, This Windows version (%A_OSVersion%) is not supported.
  ExitApp
}
 
Gui, Add, Button, x22 y80 w75 h23 gCloseApps, OK
Gui, Add, Button, x103 y80 w75 h23 gGuiClose, Cancel
Gui, Add, Text, x14 y10 w180 h15 , Please choose your device from the list:
Gui, Add, DropDownList, x16 y40 w170 h120 Choose1 vList1, 

SplashTextOn, 200, 60,, Please wait.`n Generating a list of drives on your system...
driveget, list, list  ; all drives
stringlen, len, list
loop, %len%
{
  stringleft, drive, list, 1
  If drive <> A
    driveget, label, label, %drive%:
  GuiControl,,List1, %drive%:     %label%
  stringtrimleft, list, list, 1
}
GuiControl,Choose, List1, 1
Gui, Show, h116 w200, Close Programs
SplashTextOff
Return

CloseApps:
GuiControlGet, List1
Gui, Hide
DetectHiddenWindows, On
stringleft, mydrive, List1, 2
total := EnumProcesses( pid_list )
; get PID for this script to avoid self destruction
Process, Exist
this_pid = %ErrorLevel%
loop, parse, pid_list, |
{
  lname := GetModuleFileNameEx( A_LoopField )
  If lname<>
  {                 
    ; use splitpath to obtain drive letter of each app:     
    SplitPath, lname, , , , , Drive
    ; close the program if drive matches:
    if ( Drive = mydrive AND A_LoopField <> this_pid )
    {
      WinKill, ahk_pid %A_LoopField%
      Process, Exist, %A_LoopField%
      If (ErrorLevel)
      {
        Process, Close, %A_LoopField%
        If ErrorLevel = 0
        {
          RetError := KillProcess( A_LoopField )
          If RetError = 0
            MsgBox, %lname% is not responding. `nPlease manually close this application
        }
      }
    }
  }
}
MsgBox, 64, Done, Finished processing drive %mydrive%
GuiClose:
ExitApp

EnumProcesses( byref r_pid_list )
{
   pid_list_size := 4*1000
   VarSetCapacity( pid_list, pid_list_size )
   status := DllCall( "psapi.dll\EnumProcesses", "uint", &pid_list, "uint", pid_list_size, "uint*", pid_list_actual )
   if ( ErrorLevel or !status )
      return, false
   total := pid_list_actual//4
   r_pid_list=
   address := &pid_list
   loop, %total%
   {
      r_pid_list := r_pid_list "|" ( *( address )+( *( address+1 ) << 8 )+( *( address+2 ) << 16 )+( *( address+3 ) << 24 ) )
      address += 4
   }
   StringTrimLeft, r_pid_list, r_pid_list, 1
   return, total
}

GetModuleFileNameEx( p_pid )
{
   h_process := DllCall( "OpenProcess", "uint", 0x10|0x400, "int", false, "uint", p_pid )
   if ( ErrorLevel or h_process = 0 )
      return
   name_size = 255
   VarSetCapacity( name, name_size )
   result := DllCall( "psapi.dll\GetModuleFileNameExA", "uint", h_process, "uint", 0, "str", name, "uint", name_size )
   DllCall( "CloseHandle", h_process )
   return, name
}

KillProcess( p_pid )
{
   h_process := DllCall( "OpenProcess", "uint", 0xF0000|0x100000|0xFFF, "int", false, "uint", p_pid )
   if ( ErrorLevel or h_process = 0 )
      return
   result := DllCall( "TerminateProcess", "uint", h_process, "uint", 0)
   DllCall( "CloseHandle", h_process )
   return, result
}


This version may also run a bit faster Smile ...
Back to top
View user's profile Send private message Visit poster's website
Laszlo



Joined: 14 Feb 2005
Posts: 4517
Location: Boulder, CO

PostPosted: Fri Feb 24, 2006 4:44 pm    Post subject: Reply with quote

It mercilessly ended all of the vital services, processes, except a few, included the one I referred to. PS. So far only PSKill kills that.
Back to top
View user's profile Send private message
corrupt



Joined: 29 Dec 2004
Posts: 2446

PostPosted: Sat Feb 25, 2006 8:17 pm    Post subject: Reply with quote

Thanks for giving it a try Smile . I have a few other ideas but unfortunately, until I run across a program with an issue on this machine, I wouldn't be able to do much more than keep guessing...
Back to top
View user's profile Send private message Visit poster's website
Laszlo



Joined: 14 Feb 2005
Posts: 4517
Location: Boulder, CO

PostPosted: Sat Feb 25, 2006 8:30 pm    Post subject: Reply with quote

If you run your script to end ALL processes started from C:, a few will remain. Task Manager shows them. Try to kill one of them with your script (after reboot, because some important processes could have died).
Back to top
View user's profile Send private message
corrupt



Joined: 29 Dec 2004
Posts: 2446

PostPosted: Sat Feb 25, 2006 8:46 pm    Post subject: Reply with quote

Laszlo wrote:
If you run your script to end ALL processes started from C:, a few will remain. Task Manager shows them. Try to kill one of them with your script (after reboot, because some important processes could have died).

AFAIK this effect is by design in Windows. Some may not actually still remain but have been restarted by Windows in attempt to avoid a complete system crash. Explorer restarting automatically is usually an example of this.
Back to top
View user's profile Send private message Visit poster's website
Laszlo



Joined: 14 Feb 2005
Posts: 4517
Location: Boulder, CO

PostPosted: Sat Feb 25, 2006 8:52 pm    Post subject: Reply with quote

You could call kill -9 from the command prompt with those remaining processes. If one of them responds with the access denied message, you got one.
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4517
Location: Boulder, CO

PostPosted: Sat Feb 25, 2006 9:04 pm    Post subject: Reply with quote

I need not be that secretive. The process I wanted to kill is McAfee's FrameworkService. If I am not connected to the company's intranet, this service still tries to download virus updates from an unreachable host, and during this, the PC freezes for 20 seconds. Once in every half an hour. It is not only very annoying, but some programs actually crash, I loose downloads, my internet phone stalls, etc. Its settings are protected, any change I make get ignored. It is a horribly bad design. The only remedy I have to kill that process when I am not connected (it took me days to find the cause of the freeze - I suspected some hardware problems, overheat, elco leakage, or similar). It is started by another McAfee process, which I don't want to stop, so there is no easy way to prevent FrameworkService to start in the first place. Shame on McAfee. Also, it is easy for a malicious program to kill it, so this stupid protection only makes life harder for normal users.
Back to top
View user's profile Send private message
corrupt



Joined: 29 Dec 2004
Posts: 2446

PostPosted: Sat Feb 25, 2006 9:48 pm    Post subject: Reply with quote

Thanks for clarifying. That does sound like a bad and annoying design. I'll see if I can find a candidate to experiment with. I'm currently finishing up another project but I'll create a new topic with a bit of code a bit later if testing comes up with anything interesting.
Back to top
View user's profile Send private message Visit poster's website
Loila
Guest





PostPosted: Fri Mar 21, 2008 4:56 pm    Post subject: Reply with quote

Hello and thanks for this very nice script Smile

I was looking into it to mood it for my needs and i need your help !

Autohokey is running from the portable device i want the application to close, and i need each time to relaunch my script because it was launched before other apps and is closing while other applications remains...

Is there a way to specify that this script must be the last thing to be closed? Or a way to relaunch it more nicely automaticaly at the beginning of the script?

The second question is that it's always the same device i need to eject (S:\). So the choice of the device is not usefull for me. Is there a way to modify that?

Here is my code :

Code:
^#!x::
Gui, Add, Button, x22 y80 w75 h23 gCloseApps, OK
Gui, Add, Button, x103 y80 w75 h23 gGuiClose, Cancel
Gui, Add, Text, x14 y10 w180 h15 , Please choose the drive from the list:
Gui, Add, DropDownList, x16 y40 w170 h120 Choose1 vList1,

SplashTextOn, 200, 60,, Please wait.`n Generating a list of drives on your system...
driveget, list, list  ; all drives
stringlen, len, list
loop, %len%
{
  stringleft, drive, list, 1
  If drive <> A
    driveget, label, label, %drive%:
  GuiControl,,List1, %drive%:     %label%
  stringtrimleft, list, list, 1
}
GuiControl,Choose, List1, 1
Gui, Show, h116 w200, Choose Drive
SplashTextOff
Return

CloseApps:
GuiControlGet, List1
stringleft, listres, List1, 2
mydrive := listres
total := EnumProcesses( pid_list )
loop, parse, pid_list, |
{
      lname := GetModuleFileNameEx( A_LoopField )
      If lname<>
      {                 
        ; use splitpath to obtain drive letter of each app:     
        SplitPath, lname, , , , , Drive

        ; close the program if drive matches:
        if Drive = %mydrive%
        {
          WinClose, ahk_pid %A_LoopField%
          Process, WaitClose, %A_LoopField%, 4
          If (ErrorLevel)
          {
            Process, Close, %A_LoopField%
            Process, WaitClose, %A_LoopField%, 4
            If (ErrorLevel)
              MsgBox, %lname% is not responding. `nPlease manually close this application
          }
        }
      }
}
MsgBox, Finished processing drive %mydrive%
GuiClose:
ExitApp

EnumProcesses( byref r_pid_list )
{
   if A_OSVersion in WIN_95,WIN_98,WIN_ME
   {
      MsgBox, This Windows version (%A_OSVersion%) is not supported.
      return, false
   }
   
   pid_list_size := 4*1000
   VarSetCapacity( pid_list, pid_list_size )
   
   status := DllCall( "psapi.dll\EnumProcesses", "uint", &pid_list, "uint", pid_list_size, "uint*", pid_list_actual )
   if ( ErrorLevel or !status )
      return, false
       
   total := pid_list_actual//4

   r_pid_list=
   address := &pid_list
   loop, %total%
   {
      r_pid_list := r_pid_list "|" ( *( address )+( *( address+1 ) << 8 )+( *( address+2 ) << 16 )+( *( address+3 ) << 24 ) )
      address += 4
   }
   
   StringTrimLeft, r_pid_list, r_pid_list, 1
   
   return, total
}

GetModuleFileNameEx( p_pid )
{
   if A_OSVersion in WIN_95,WIN_98,WIN_ME
   {
      MsgBox, This Windows version (%A_OSVersion%) is not supported.
      return
   }

   h_process := DllCall( "OpenProcess", "uint", 0x10|0x400, "int", false, "uint", p_pid )
   if ( ErrorLevel or h_process = 0 )
      return
   
   name_size = 255
   VarSetCapacity( name, name_size )
   
   result := DllCall( "psapi.dll\GetModuleFileNameExA", "uint", h_process, "uint", 0, "str", name, "uint", name_size )
   
   DllCall( "CloseHandle", h_process )
   
   return, name
}


Thanks a lot for help Smile
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page Previous  1, 2, 3
Page 3 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group