Making a "process_ending.exe".

Do you have a technical question that doesn't really fit a specific console? Want some general info on electronics, hacking, making cookies, etc? Here's the place to ask! Go nuts.

Moderator: Moderators

Mikeyman64
Posts: 493
Joined: Tue Feb 21, 2006 5:06 pm
Location: End of the World, AWKI
Contact:

Making a "process_ending.exe".

Post by Mikeyman64 »

How do I go about making an executing file that closes a certain process? Or better yet, closes a process and then opens it back up again.
Go Here! On Your Wii!

Matt. 5:27
gannon
Moderator
Posts: 6974
Joined: Sun Apr 04, 2004 4:48 pm
Location: Near that one big lake
Contact:

Post by gannon »

What OS? I'd assume windows because of the .exe, but still, which version would help. I have little/no experience with kill commands for windows/DOS though
Mikeyman64
Posts: 493
Joined: Tue Feb 21, 2006 5:06 pm
Location: End of the World, AWKI
Contact:

Post by Mikeyman64 »

Sorry,
It's for a Windows XP Home w/SP2 system.
Go Here! On Your Wii!

Matt. 5:27
Skyone
Moderator
Posts: 6390
Joined: Tue Nov 29, 2005 8:35 pm
Location: it is a mystery
Contact:

Post by Skyone »

Couple of ways.
  • BATCH Code (easiest):

Code: Select all

@echo off
taskkill /IM TaskName.exe
That will close the program but will ask if you want to save (e.g. Word, Notepad). If you want to close it forcefully:
  • BATCH Code Force:

Code: Select all

@echo off
taskkill /F /IM TaskName.exe
  • C++:

Code: Select all

#include <cstdio>
#include <stdlib.h> 

int main()
{
  system("taskkill /IM TaskName.exe");
  return 0;
}
  • C++ Force:

Code: Select all

#include <cstdio>
#include <stdlib.h> 

int main()
{
  system("taskkill /F /IM TaskName.exe");
  return 0;
}

Haven't tested any of this, but it should work fine.

If you need any other language, just ask.
vb_master
Moderator
Posts: 4793
Joined: Tue Jun 08, 2004 9:52 pm

Post by vb_master »

Just tested the C++ forced one, works good on Half-Life 2.
Mikeyman64
Posts: 493
Joined: Tue Feb 21, 2006 5:06 pm
Location: End of the World, AWKI
Contact:

Post by Mikeyman64 »

I guess I just write this C++ into a text editor and save it as a .exe?

EDIT: After I did the above (my text editor idea) windows gives me a 16-bit DOS error message that says that the NTVDM CPU has encountered an illegal instruction.
Go Here! On Your Wii!

Matt. 5:27
bicostp
Moderator
Posts: 10491
Joined: Mon Mar 07, 2005 5:47 pm
Steam ID: bicostp
Location: Spamalot
Contact:

Post by bicostp »

No, you need a C++ compiler.

You can make a batch file the way you described. (Write it in Notepad and save it as a .BAT file.) It will work without any compilation.

EDIT: Yes you can. Just add a line to the batch file that runs the program. (Just put in the full path name, such as C:\WINDOWS\SYSTEM32\SOL.EXE for solitaire.)
Last edited by bicostp on Fri May 04, 2007 9:23 pm, edited 1 time in total.
Mikeyman64
Posts: 493
Joined: Tue Feb 21, 2006 5:06 pm
Location: End of the World, AWKI
Contact:

Post by Mikeyman64 »

Is there a way I can fit a batch code in the same file that will open the file back up after it closes?
Go Here! On Your Wii!

Matt. 5:27
Skyone
Moderator
Posts: 6390
Joined: Tue Nov 29, 2005 8:35 pm
Location: it is a mystery
Contact:

Post by Skyone »

Mikeyman64 wrote:Is there a way I can fit a batch code in the same file that will open the file back up after it closes?
Say what? You want a batch code that will re-open the program?
Mikeyman64
Posts: 493
Joined: Tue Feb 21, 2006 5:06 pm
Location: End of the World, AWKI
Contact:

Post by Mikeyman64 »

Yay! I figured it out myself! I feel smart!

"@echo off
taskkill /F /IM TaskName.exe

cd C:\windows\system32\
start SameTaskName.exe"

without quotes


Now, how would I do that in C++?

EDIT: I figured out that I really need it in C++ because the PC I'm making this for (my parents) is running XP Home which doesn't support taskkill.
Go Here! On Your Wii!

Matt. 5:27
Skyone
Moderator
Posts: 6390
Joined: Tue Nov 29, 2005 8:35 pm
Location: it is a mystery
Contact:

Post by Skyone »

Well, there's a extremely better way to do it, using registry and stuff, but this is fine enough. :P

In C++, I am just using the "system" shell, which basically just makes your program act like a batch file or command prompt. You can also use C++ commands such as rename(), delete() (more in FileOperations.h).

So just...

Code: Select all

#include <cstdio>
#include <stdlib.h>

int main()
{
  system("taskkill /F /IM TaskName.exe");
  system("cd C:\windows\system32\");
  system("start SameTaskName.exe");
  return 0;
}
Once again, untested. :P

So why do you want to do this? What's the program's purpose?
Mikeyman64
Posts: 493
Joined: Tue Feb 21, 2006 5:06 pm
Location: End of the World, AWKI
Contact:

Post by Mikeyman64 »

My dad's printer spooling service (spoolsv.exe) keeps locking up on him. I think it happens when a print project starts but doesn't finish and then someone else comes along and starts another print project and it gets all screwy, I've got 9 sib still in my house and that kind of thing will happen, and I found that if I close spoolsv.exe and then start it back up it works, so wanted to make my, un-technological, dad an easy way out of this. The first thing that came to my mind was and easy exe right there on the desktop.

Yikes! That was bad writing! I'm too tired to fix it though...zzzzzzzzz
Go Here! On Your Wii!

Matt. 5:27
Skyone
Moderator
Posts: 6390
Joined: Tue Nov 29, 2005 8:35 pm
Location: it is a mystery
Contact:

Post by Skyone »

That's like, the worst way ever! :P

-Start > Run > regedit >

-HKEY_CURRENT_USER > Software > Microsoft > Windows > CurrentVersion > Run

-Delete the spoolsv.exe REG_SZ subkey entry. Just click it and press the delete key.

EDIT: Forgot to explain what it does. It will stop spoolsv.exe from booting up at the start of Windows.
Mikeyman64
Posts: 493
Joined: Tue Feb 21, 2006 5:06 pm
Location: End of the World, AWKI
Contact:

Post by Mikeyman64 »

spoolsv.exe=good
spoolsv.exe_when it's not working=bad

I'm not trying to get rid of it. If I do that my printer spooling won't work.
Go Here! On Your Wii!

Matt. 5:27
vb_master
Moderator
Posts: 4793
Joined: Tue Jun 08, 2004 9:52 pm

Post by vb_master »

If you lock down the computer with Deep Freeze nothing bad could go wrong.
Post Reply