I want to kill exe from Task Manager - vb.net

i have one exe,when this exe is called ,some this is exe is already open in task manager,i want kill all previous exe not current exe,i am using VB.net

As previous commenters have noted, you really should make more of an effort to solve the problem yourself (and demonstrate you've tried already)
Saying that, here are a few hints:
taskkill.exe /F /IM myprocess.exe /FI "PID ne 555"
Process.GetProcessesByName
Process.GetCurrentProcess
Process.Kill
Be very careful killing processes. As Anton Kovalenko noted already, are you really sure you want to do it? It may be better to simply warn of the condition and provide instruction to the user/admin.

Set your program up to receive messaging. When the most current instance launches have it send a message to the previous instance to itself shutdown gracefully - and of course put the code in place to do this.

Related

How to check if another instance of the app/binary is already running

I'm writing a command line application in Mac using Objective-c
At the start of the application, i want to check if another instance of the same application is already running. If it is, then i should be either wait for it to finish or exit the current instance or quit the other instance etc.
Is there any way of doing this?
The standard Unix solution for this is to create a "run file". When you start up, you try to create that file and write your pid to it if it doesn't exist; if it does exist, read the pid out of it, and if there's a running program with that pid and your process name, wait/exit/whatever.
The question is, where do you put that file, and what do you call it?
Well, first, you have to decide what exactly "already running" means. Obviously not "anywhere in the world", but it could be anything from "anywhere on the current machine" to "in the current desktop session". (For example, if User A starts your program, pauses it, then User B comes along and takes over the computer via Fast User Switching, should she be able to run the program, or not?)
For pretty much any reasonable answer to that question, there's an obvious pathname pattern. For example, on a Mac, /tmp is shared system-wide, while $TMPDIR is specific to a given session, so, e.g., /tmp/${ARGV[0]}.pid is a good way to say "only one copy on the machine, period", while ${TMPDIR}/${ARGV[0]}.pid is a good way to say "only one copy per session".
Simple but common way to do this is to check the process list for the name of your executable.
ps - A | grep <your executable name>
Thank you #abarnert.
This is how I have presently implemented. At the start of the main(), I would check if a file named .lock exists in the binary's own directory (I am considering moving it to /tmp). If it is, application exits.
If not, it would create the file.
At the end of the application, the .lock file is removed
I haven't yet written the pid to that file, but I will when exiting the previous instance is required (as of yet I don't need it, but may in the future).
I think PID can be retrieved using
int myPID=[[NSProcessInfo processInfo] processIdentifier];
The program will be invoked by a custom scheduler which is running as a root daemon. So it would be run as root.
Seeing the answers, I would assume that there is no direct method of solving the problem.

Some one help me please, cpumun.exe irritating me

My CPU is running at 100% even though it should be idle. The task manager shows that a single process called 'cpumin.exe' is causing this.
Could anyone please explain what I can do to stop this? As whenever I kill the process, it just starts again.
I have noticed kind of relationship between this process and network, because when I unplug the network cable the computer works well.
And there is something else when I give this process the order "Suspend process" and when you open the "Analyze Wait Chain" I found that this process have this message "One or more threads of cpumin.exe are waiting to finish network I/O".
Thanks...
Someone else had a similar problem here ...
What exactly is the 'cpumin.exe' process which runs in the background and takes up 100% of the CPU? It happens whenever I run a Java program
Probably best to do a full virus scan just in case. According to http://www.threatexpert.com/report.aspx?md5=dd6da7e7b46f199edc8e4a81b2ae5e1e, it could be some sort of mass mailer.
try the following:
Click Start > Run > (type "cmd.exe" without quotation) > Enter
a Command line (black screen will appear) type the following:
taskkill /fi "imagename eq cpumun.exe" /f /t
The above command will surely kill the task and all of its child processes and tree.
cpumin.exe appears to be a virus, see:
http://www.threatexpert.com/report.aspx?md5=dd6da7e7b46f199edc8e4a81b2ae5e1e

Observe a Process of Unknown PID (no UI)

I've found this question, but even when is close to what I need, is useless
Basically, I have an app that needs to do something when another process (of known name) is launched and/or terminated, but i don't have the PID, so i can't set a kqueue to look for it.
I could do a while for "ps aux | grep processtolook | grep -v grep" command, but that's my last resort.
Any ideas?
Look at this answer: Determine Process Info Programmatically in Darwin/OSX. The libproc.h header file has proc_listpids which will get you all the pids. You can then get the pid information in a loop and using proc_pidinfo and check the name. Looking at the top source as suggested there might also be worthwhile. (The current verson is here http://www.opensource.apple.com/source/top/top-67/.)
Unfortunately, this is an undocumented interface and subject to change at any time. Also, it isn't the quickest thing, since you have to loop over all the processes in the system. In general, this isn't a great way to do this.
A better way might be to write a new processtolook that simply invoked the old one which you can move or rename. It could then notify you of the process start and stop. Is that a possibility?
If the target process/program name which you want the PID is "processtolook" then you can use pidof command to get the PID of that running program.
pidof processtolook
have a look at the pidof manual. This is a part of sysvinit-tools package.
EDIT1:
Have a look at this code i found: http://programming-in-linux.blogspot.com/2008/03/get-process-id-by-name-in-c.html
This might help you get you the outline.
On BSD you can use kvm_openfiles and kvm_getprocs to implement what you want. I don't know if it's available on OSX. If you have a pgrep program, look how it's implemented (src/bin/pkill.c).

Kill process after launching with AuthorizationExecuteWithPrivileges

If I launched a shell script using AuthorizationExecuteWithPrivileges what would be the easiest way to kill the script and any other processes that it spawned.
Thanks
It's running as root, so you can't kill it from a regular-user process. You're going to have to ask it nicely to exit on its own.
Apple has sample code that uses stdout to pass the PID back to the caller.
Use the communications pipe that AuthorizationExecuteWithPrivileges() returns by reference in its last argument, FILE **communicationPipe, to send a message to the child process that asks it to take itself and its descendants out. It can then kill itself and all its descendants using kill(0, SIGINT), or, if more drastic measures are required, SIGKILL.
The message you use can be as simple as closing the file while the child waits for the file to close; at that point, it knows you're done talking to it and it's time to take itself out.
There are some caveats about the descendants that will actually receive this message, for which see the kill(2) manpage. The caveats mostly won't matter so long as the process you started via AEWP hasn't dropped privileges, though one implicit issue is that this approach won't work if any child processes have put themselves in a new process group.

How to get information about what code is running in a thread?

I have a Window Forms application (using clickonce installation, running on a terminal server) that occasionaly ends up with a thread that appears to be running in a tight loop. The user doesn't know this happens as the app continues to run as expected. Also I have determined that I can kill the problem thread without any apparent affect on the app.
I can use Process Explorer to find the instance of an app with the problem and can isolate the thread with the problem but haven't found any way to look into the thread to find anything that would help me determine what is causing the problem. Does anyone know of a way to some additional information about a thread, like maybe strings, that would help me zero in on the issue?
Thanks,
Dave
Haven't tried this myself but "Process Monitor" claims it "shows real-time file system, Registry and process/thread activity"
http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx
Hope this helps.
You should be able to attach Visual Studio to the running process to get more information. Provided the .pdb files are included with the application and you have source code for the avialable version you should be able to use the Threads window combined with pausing / stepping through to see just what the code is doing.