 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
help Guest
|
Posted: Sat Jun 16, 2007 7:21 pm Post subject: Need help with a simple script |
|
|
I'm having troubles with my computer and I'm kind of in a bind here.
I was hoping someone could show me an example of a script I need
I need to quit iexplore.exe in a loop, but I need to leave one process running for the trend micro housecall. The process I need running's PID is 204. I was wondering if there's a way to close all iexplore.exe processes that don't have the 204 PID.
Any help is much appreciated. |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6772 Location: Pacific Northwest, US
|
Posted: Sat Jun 16, 2007 9:07 pm Post subject: |
|
|
TESTED
It shows the msgbox of all PIDs first, then a msgbox of each explorer PID that is NOT the keep PID. If you hit OK, it will close that PID. Hit Escape if it shows the PID you want to keep and it shouldn't close it.
| Code: |
keep = 204
;adapted from example 4 of Process command
; Example #4: Retrieves a list of running processes via DllCall then shows them in a MsgBox.
d = `n ; string separator
s := 4096 ; size of buffers and arrays (4 KB)
Process, Exist ; sets ErrorLevel to the PID of this running script
; Get the handle of this script with PROCESS_QUERY_INFORMATION (0x0400)
h := DllCall("OpenProcess", "UInt", 0x0400, "Int", false, "UInt", ErrorLevel)
; Open an adjustable access token with this process (TOKEN_ADJUST_PRIVILEGES = 32)
DllCall("Advapi32.dll\OpenProcessToken", "UInt", h, "UInt", 32, "UIntP", t)
VarSetCapacity(ti, 16, 0) ; structure of privileges
InsertInteger(1, ti, 0, 4) ; one entry in the privileges array...
; Retrieves the locally unique identifier of the debug privilege:
DllCall("Advapi32.dll\LookupPrivilegeValueA", "UInt", 0, "Str", "SeDebugPrivilege", "UIntP", luid)
InsertInteger(luid, ti, 4, 8)
InsertInteger(2, ti, 12, 4) ; enable this privilege: SE_PRIVILEGE_ENABLED = 2
; Update the privileges of this process with the new access token:
DllCall("Advapi32.dll\AdjustTokenPrivileges", "UInt", t, "Int", false, "UInt", &ti, "UInt", 0, "UInt", 0, "UInt", 0)
DllCall("CloseHandle", "UInt", h) ; close this process handle to save memory
hModule := DllCall("LoadLibrary", "Str", "Psapi.dll") ; increase performance by preloading the libaray
s := VarSetCapacity(a, s) ; an array that receives the list of process identifiers:
DllCall("Psapi.dll\EnumProcesses", "UInt", &a, "UInt", s, "UIntP", r)
Loop, % r // 4 ; parse array for identifiers as DWORDs (32 bits):
{
id := ExtractInteger(a, A_Index * 4)
; Open process with: PROCESS_VM_READ (0x0010) | PROCESS_QUERY_INFORMATION (0x0400)
h := DllCall("OpenProcess", "UInt", 0x0010 | 0x0400, "Int", false, "UInt", id)
VarSetCapacity(m, s) ; an array that receives the list of module handles:
DllCall("Psapi.dll\EnumProcessModules", "UInt", h, "UInt", &m, "UInt", s, "UIntP", r)
VarSetCapacity(n, s, 0) ; a buffer that receives the base name of the module:
e := DllCall("Psapi.dll\GetModuleBaseNameA", "UInt", h, "UInt", m, "Str", n, "Chr", s)
DllCall("CloseHandle", "UInt", h) ; close process handle to save memory
If n ; if image is not null add to list:
l = %l%%n%-%id%%d%
}
DllCall("FreeLibrary", "UInt", hModule) ; unload the library to free memory
; Remove the first and last items in the list (possibly ASCII signitures)
StringMid, l, l, InStr(l, d) + 1, InStr(l, d, false, 0) - 2 - InStr(l, d)
StringReplace, l, l, %d%, %d%, UseErrorLevel ; gets the number of processes
;Sort, l, C ; uncomment this line to sort the list alphabetically
MsgBox, 0, %ErrorLevel% Processes, %l%
loop, parse, l, `n, `r
{
If (InStr(A_LoopField, "explorer") and !InStr(A_LoopField, %keep%))
{
PID := SubStr(A_LoopField, InStr(A_LoopField, "-")+1)
Msgbox, %PID%
Process, Close, %PID%
}
}
ExtractInteger(ByRef pSource, pOffset = 0, pIsSigned = false, pSize = 4) ; See DllCall for details.
{
Loop %pSize% ; Build the integer by adding up its bytes.
result += *(&pSource + pOffset + A_Index-1) << 8*(A_Index-1)
if (!pIsSigned OR pSize > 4 OR result < 0x80000000)
return result ; Signed vs. unsigned doesn't matter in these cases.
return -(0xFFFFFFFF - result + 1)
}
InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
{
Loop %pSize% ; Copy each byte in the integer into the structure as raw binary data.
DllCall("RtlFillMemory", "UInt", &pDest + pOffset + A_Index-1, "UInt", 1, "UChar", pInteger >> 8*(A_Index-1) & 0xFF)
}
Esc::ExitApp
|
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
Jon
Joined: 28 Apr 2004 Posts: 373
|
Posted: Sat Jun 16, 2007 9:55 pm Post subject: |
|
|
| Code: | ^!z::
WinGet, Count, Count, ahk_class IEFrame
loop, %Count%
{
WinGet, PID, PID, ahk_class IEFrame
If PID <> 204
{
winclose, ahk_pid %PID%
winWaitClose, ahk_pid %PID%
}
}
return |
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|