Hello everyone,
I have a fairly show PC, and before i start a heavy game i have to kill all background programs (like MSN, Internet Explorer, Windows Explorer, etc)
Currently i am doing that manually every time via the task manager, but i wonder, is it with purebasic possible to kill those programs automatically? Like, creating a "Game mode" for my pc?
The program would have to check or a certain service, (like msnmessenger.exe) is running, and if so, kill it.
Can this be done, and if so how?
Not looking for code, a general direction where to look will suffice.
Thanks in advance!
Killing programs / processes with purebasic?
Killing programs / processes with purebasic?
User of PB 4.41 - x86
On Windows 7
Intel Core I5 2.26GHZ
8 GB RAM
ATI Mobility Radeon HD 5650
On Windows 7
Intel Core I5 2.26GHZ
8 GB RAM
ATI Mobility Radeon HD 5650
Re: Killing programs / processes with purebasic?
Well, it's not exactly 'killing' but you could send 'close' messages to each application.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Re: Killing programs / processes with purebasic?
Code: Select all
SendMessage_(FindWindow_(0, "Windows Live Messenger"), #WM_CLOSE, 0, 0)
Or use TerminateProcess_() which is same as killing process with TaskManager:
Code: Select all
EnableExplicit
Procedure GetPidFromName(Name.s)
Protected result
Protected Process.PROCESSENTRY32
Protected ProcSnap = CreateToolhelp32Snapshot_(#TH32CS_SNAPPROCESS, 0)
If ProcSnap <> #ERROR_INVALID_HANDLE
Process\dwsize = SizeOf(PROCESSENTRY32)
If Process32First_(ProcSnap, Process) = #True
While Process32Next_(ProcSnap, Process) <> #False
If Trim(PeekS(@Process\szExeFile,#MAX_PATH)) = Name.s
result = Process\th32ProcessID
Break
EndIf
Wend
EndIf
CloseHandle_(ProcSnap)
EndIf
ProcedureReturn result
EndProcedure
Procedure TerminateProcess(Name.s, ExitCode = 0)
Protected result
Protected processID = GetPidFromName(Name.s)
If processID
Protected hProcess = OpenProcess_(#PROCESS_TERMINATE, #False, processID)
If hProcess
If TerminateProcess_(hProcess, ExitCode)
result = #True
EndIf
CloseHandle_(hProcess)
EndIf
EndIf
ProcedureReturn result
EndProcedure
;test:
If TerminateProcess("msnmsgr.exe")
Debug "success"
Else
Debug "failed to terminate process"
EndIf