AutoHotkey Community

It is currently May 27th, 2012, 9:22 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 42 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject:
PostPosted: February 23rd, 2006, 3:32 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Thanks! PSKill ended the process with a single call.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2006, 5:30 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
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...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2006, 10:39 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
@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 :lol: ... 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 :) ...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2006, 4:44 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2006, 8:17 pm 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
Thanks for giving it a try :) . 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...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2006, 8:30 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2006, 8:46 pm 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2006, 8:52 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2006, 9:04 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2006, 9:48 pm 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2008, 4:56 pm 
Hello and thanks for this very nice script :)

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 :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 31st, 2010, 1:26 pm 
Offline

Joined: January 17th, 2010, 1:38 am
Posts: 4
Hello EveryBody,

i dont know if am i on good topic but
Can anyone please help me out how can i write or is it possible to write in hotkey,
i would like a hotkey or some macro or something which is
"Closing every programs" in "Windows XP" like "explorer.exe" too, and block USB pendrive etc and don't let using anything in windows, just Open 1 .xls (excel) file and make it full screen and can only work in it and saving it thats all nothing else will work just that only 1 excel file
is it posibble to make and how what do i need to write in hotkey
can anyone help me please ?

Thank You very much and sorry for newbie


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 42 posts ]  Go to page Previous  1, 2, 3

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Google Feedfetcher, migz99, Yahoo [Bot] and 66 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group