How can I close another running program by reference of the file (.exe) name?
How can I close another running program by reference of the file (.exe) name?
Use EnumProcesses() to get a list of all the running processes. Then use OpenProcess() on each of them to get handles. Once you've got the handle you can use GetModuleFileName() to see if that process matches your filename, and if it does, use something like TerminateProcess() to close it.
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
I can't do it. I don't even know the syntax of EnumProcesses(), and google didn't find me anything I could understand.
If it's not to much trouble do you think you could show me how to list the current processes?
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
Okey dokes, It's a compiler problem I have now.
I'm using dev-c++ and I'm getting this error:
[Linker error] undefined reference to `EnumProcesses@12'
My code it this:
Thanks for the help so far.Code:#include <iostream> #include <stdlib.h> #include <psapi.h> using namespace std; int main(int argc, char *argv[]) { DWORD aProcesses[1024],cbNeeded; EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ); system("PAUSE"); return 0; }
Did you see this example ? Does it help you?
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Yup. I guess it's just the compiler. Looks like I'll have to strengthen the Gates Empire more by buying Visual C++, which was the last thing I wanted to do because I don't have a job and it'll take my life savings to get a copy (I'm only 16).
>>> I guess it's just the compiler.
From memory, those headers and libraries are not in the standard compiler stuff, they are included with the Platform SDK. Have you downloaded that?
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
What's that and where can I get it? I've seen it metioned in many places and I guess it stands for software dev. kit and that it probably aids in developing for win32 platform but that's about all I guess..
If you could please elaborate I'd be very grateful.
I just killed my SDK and tried to compile this...
... and got exactly the same error as you. Reinstall the SDK, (actually re-link it to VC), and the thing compiles and runs fine, so I would definitely try this first.Code:#include <windows.h> #include <psapi.h> #include <iostream> using namespace std; int main() { DWORD Pids[100]; DWORD BytesUsed; int RetVal; RetVal = EnumProcesses(Pids, sizeof(Pids), &BytesUsed); cout << "There are " << (BytesUsed/sizeof(DWORD)) << " processes." << endl; return 1; }
There are a few different SDK's some are only interesting if you have other bits of software, look here. Warning! Some of these downloads are very big!
*** EDIT ***
Your guesses as to what it is and what the SDK stand for are correct.
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
Okey dokey, since I'm on a 56k and I'm almost over my 500mb download limit for the month (can't get broadband where I live ) I have to wait a few days to start the download and then probably a day for it to download.
I'll be back sometime in the next few days.
Thanks for all your help so far.
The other routines I mentioned are in the standard windows.h, so you should be able to try them out, and maybe write a program which allows you to manually enter a PID. That way, when you've got the SDK you'll only need to stick that bit on the front.
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
The PSAPI stuff isnt accessable easilly with the standard includes and libs that comne with VC++, you need the SDK (as adrian said).
I have been caught needing these funcs before on a clean install of my compiler (same problem as you - a 100MB+ download on 56K is a swine!), so if your in a tight place you can manually do the loading yourself...
Here's an example I used of getting EnumProcesses without the SDK - http://cboard.cprogramming.com/showt...=enumprocesses
Might give you an option for now until you have downloaded the SDK (PS....I have broadband now - definately worth the upgrade )