Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How To Kill A Process From Your Application

Featured Replies

Posted

hi

I like to ask that how can i kill or close a process from my code

suppose a process is already running in the memory e.g Notepad opened or some game is running than how can we close it from our code.

(languages can be any :masm, c++, vb).

Hi,I will explain this using the example of "Notepad". Suppose you have an instance of Notepad running, with the title "untitled - Notepad". To kill this from your application , you need to do the following :-

Declare the functions from user32.dll

public const int WM_SYSCOMMAND = 0x0112;
public const int SC_CLOSE = 0xF060;
[DllImport("user32.dll")]
public static extern int FindWindow(
string lpClassName, // class name
string lpWindowName // window name
);
[DllImport("user32.dll")]
public static extern int SendMessage(
int hWnd, // handle to destination window
uint Msg, // message
int wParam, // first message parameter
int lParam // second message parameter
);

Then use the following to close the procces

		
string myClass = "notepad"; string myTitle = "untitled - Notepad";
int HND = FindWindow(myclass, myTitle); //returns the handle of the window.
if (HND != 0 )
{
int retn = SendMessage(HND, Win32.WM_SYSCOMMAND, Win32.SC_CLOSE, 0); //Sends the message to that process to close.
}

The above is in C#, hope you can do this in VB(almost the same).

Oricode.

Edited by oricode

You can use these functions:

GetWindowThreadProcessId, OpenProcess, TerminateProcess.

Look them up here for details:

http://msdn2.microsoft.com/en-us/default.aspx

Edited by GaBoR

hi

use this to kill a another app

.data
szProcs db "notepad.exe",0
KillProcess Proc _IdProcess:DWORD
LOCAL uProcess:PROCESSENTRY32
LOCAL hSnapshot:DWORD
mov uProcess.dwSize, sizeof uProcess
invoke CreateToolhelp32Snapshot, TH32CS_SNAPPROCESS, 0
mov hSnapshot, eax
invoke Process32First, hSnapshot,addr uProcess
.while eax
xor ecx, ecx
lea esi, [uProcess.szExeFile]
mov ebx, esi
dec ebx
invoke lstrlen, esi
add esi, eax
.while esi!=ebx
invoke lstrcmpi, esi, _IdProcess
.if !eax
invoke OpenProcess, PROCESS_TERMINATE, 1, uProcess.th32ProcessID
invoke TerminateProcess, eax, 0
jmp done
.endif
; optimize this
dec esi
.endw
invoke Process32Next, hSnapshot, ADDR uProcess
.endw
done:
invoke CloseHandle, hSnapshot
ret
KillProcess endp

greets

ragdog

Edited by ragdog

  • Author

Thanks All of you for your kind suggestions. I have understood all the three styles to Kill another process.

Thank you all again :flowers::flowers::flowers::flowers::flowers:

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.