Solved

How to create a background process ?

Posted on 2001-06-13
33
264 Views
Last Modified: 2010-04-02
I want to make my program as a background process on Win9x (or as a Service on WinNT/2000). That means users will not know the process is running, and the task manager will only show the process on the "Processes" tab, NOT on the "Applications" tab.

*** I want to do it by using API calls. ***

Please tell me how to do it.
Which API calls can help ?
Also, the code should work on Win9x/NT/2000/ME.

Thanx!


MW
0
Comment
Question by:raymng
  • 13
  • 7
  • 5
  • +5
33 Comments
 
LVL 5

Expert Comment

by:proskig
ID: 6187601
Look for examples on this page
http://www.codeguru.com/system/index.shtml
0
 
LVL 32

Expert Comment

by:jhance
ID: 6187602
You start a new process from one application using the Windows CreateProcess() API call.  In the STARTUPINFO structure you can specify that the window should be hidden (i.e. it won't show up on the desktop or on the taskbar) if you set wShowWindow to SW_HIDE and the dwFlags to include STARTF_USESHOWWINDOW.
0
 
LVL 32

Expert Comment

by:jhance
ID: 6187671
>>>*** I want to do it by using API calls. ***

What OTHER way is there?
0
 
LVL 30

Expert Comment

by:Axter
ID: 6187865
Just by using the ShowWindow API, you can get your program out of the "Application Tab".

ShowWindo(hWnd,SW_HIDE);
0
 
LVL 30

Expert Comment

by:Axter
ID: 6187869
Oops! type-o
That should have been:

ShowWindow(hWnd,SW_HIDE);
0
 

Author Comment

by:raymng
ID: 6187991
Axter:

"ShowWindow(hWnd,SW_HIDE)" does not work, my program still appear on the Application Tab of task manager.


regards,
MW
0
 
LVL 32

Expert Comment

by:jhance
ID: 6188081
Since you choose to totally ignore my comment, I'll have to post it again as an ANSWER this time....


You start a new process from one application using the Windows CreateProcess() API call.  In the STARTUPINFO
structure you can specify that the window should be hidden (i.e. it won't show up on the desktop or
on the taskbar) if you set wShowWindow to SW_HIDE and the dwFlags to include STARTF_USESHOWWINDOW.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6188144
Where in your application did you put ShowWindow?
Make sure you're hiding the main window of your application.

I just tested it out on an NT4.0 machine, and it did take it out of the Application Tab.

What OS are you using?

jhance,
I think the questioner is referring to the current application, and not a newly launched application.
0
 
LVL 32

Expert Comment

by:jhance
ID: 6188434
>>I think the questioner is referring to the current application, and not a newly launched application.

That may well be but he could at least tell me to go take a hike...
0
 
LVL 30

Expert Comment

by:Axter
ID: 6188849
I agree. :-)
0
 

Author Comment

by:raymng
ID: 6189619
Axter, jhance:

As Axter said, my question is referring to the current application, and not a newly launched application, so I can't accept your answer, jhance. Sorry.

I am using Win2000 Prof.
I did try to hide the main window of my application.
However, "ShowWindow(hWnd,SW_HIDE)" does not hide my program, it still appear on the Application Tab of task manager.

What can I do ?


regards,
MW
0
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6189749
Just to clear something.
Do You want this:
To see active window from your application, and to not see this in taskbar ?
0
 

Author Comment

by:raymng
ID: 6189787
No.
My application will totally hide from users, only the TASK MANAGER will show my application on the "Processes" tab ( NOT on the "Applications" tab).

Please help!!!


Regards,
MW
0
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6189805
Is any visual component in your application (Windows) ?
0
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6189808
Is any visual component in your application (Windows) ?
0
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6189812
Is any visual component in your application (Windows) ?
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6189814
Is any visual component in your application (Windows) ?
0
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6189816
Is any visual component in your application (Windows) ?
0
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6189817
Is any visual component in your application (Windows) ?
0
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6189818
Sorry !
Some error with Opera automatic reload option.
0
 

Author Comment

by:raymng
ID: 6189835
Yes. One dialog like windows, but it is useless, just for debuging and testing. Users will not interact with it.


MW
0
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6189878
Is this window visible ?
0
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6189897
Is this window visible ?
0
 

Author Comment

by:raymng
ID: 6189898
No, it is not visible.
0
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6189911
Is it Visual C MFC application ?
0
 

Author Comment

by:raymng
ID: 6189927
Is it relevant ?
0
 
LVL 2

Accepted Solution

by:
MadYugoslav earned 100 total points
ID: 6189961
It may be.
In MFC if this is dialog based application or MDI/SDI in InitInstance of your application after You create main window and set m_pMainWnd to that window You should call m_pMainWnd->ShowWindow(SW_HIDE).
0
 

Author Comment

by:raymng
ID: 6189979
Did you test it ?
In Win2000, my application still show on Application tab of task manager.

MW
0
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6189993
I use Windows 2000 Pro.
This is what I use in a few applications.
Can You post your initinstance, and kind of application DLG/MDI/SDI and DLL/EXE ?
0
 
LVL 1

Expert Comment

by:Viesturs
ID: 6203010
If you wanna hide program from task manager you can use

typedef DWORD (__stdcall *pRegFunction)(DWORD, DWORD);

     HINSTANCE          hKernelLib;
     pRegFunction     RegisterServiceProcess;

     hKernelLib = LoadLibrary("kernel32.dll");
     if (hKernelLib){
      RegisterServiceProcess = (pRegFunction)GetProcAddress(hKernelLib, "RegisterServiceProcess");
      if (RegisterServiceProcess)
         RegisterServiceProcess(GetCurrentProcessId(), 1);
     }
0
 
LVL 1

Expert Comment

by:jizhang
ID: 6203435
Why not simply use:

ShellExecute(m_hWnd, "open", "C:\\BIN\\my.exe",NULL, NULL, SW_HIDE);

"...", may be in format _T("..."),
if you have parameters, fill out in 4th arg.




0
 
LVL 30

Expert Comment

by:Axter
ID: 6203444
jizhang,
The questioner is trying to do this to the current program, not one he/she is trying to launch.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6678405
Please return to this question and finalize it.  It is nearly 6 months later, much help offered and still open.  

Indidentally, I've advised you on another question that homework questions are covered in the Guidelines and Agreement in terms of acedemic honesty.  Details c/o the Help Desk link on the left.

Moondancer
Community Support Moderator @ Experts Exchange
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now