How to create a background process ?

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
RaymondAsked:
Who is Participating?
 
MadYugoslavConnect With a Mentor Commented:
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
 
proskigCommented:
Look for examples on this page
http://www.codeguru.com/system/index.shtml
0
 
jhanceCommented:
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
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
jhanceCommented:
>>>*** I want to do it by using API calls. ***

What OTHER way is there?
0
 
AxterCommented:
Just by using the ShowWindow API, you can get your program out of the "Application Tab".

ShowWindo(hWnd,SW_HIDE);
0
 
AxterCommented:
Oops! type-o
That should have been:

ShowWindow(hWnd,SW_HIDE);
0
 
RaymondAuthor Commented:
Axter:

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


regards,
MW
0
 
jhanceCommented:
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
 
AxterCommented:
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
 
jhanceCommented:
>>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
 
AxterCommented:
I agree. :-)
0
 
RaymondAuthor Commented:
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
 
MadYugoslavCommented:
Just to clear something.
Do You want this:
To see active window from your application, and to not see this in taskbar ?
0
 
RaymondAuthor Commented:
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
 
MadYugoslavCommented:
Is any visual component in your application (Windows) ?
0
 
MadYugoslavCommented:
Is any visual component in your application (Windows) ?
0
 
MadYugoslavCommented:
Is any visual component in your application (Windows) ?
0
 
MadYugoslavCommented:
Is any visual component in your application (Windows) ?
0
 
MadYugoslavCommented:
Is any visual component in your application (Windows) ?
0
 
MadYugoslavCommented:
Is any visual component in your application (Windows) ?
0
 
MadYugoslavCommented:
Sorry !
Some error with Opera automatic reload option.
0
 
RaymondAuthor Commented:
Yes. One dialog like windows, but it is useless, just for debuging and testing. Users will not interact with it.


MW
0
 
MadYugoslavCommented:
Is this window visible ?
0
 
MadYugoslavCommented:
Is this window visible ?
0
 
RaymondAuthor Commented:
No, it is not visible.
0
 
MadYugoslavCommented:
Is it Visual C MFC application ?
0
 
RaymondAuthor Commented:
Is it relevant ?
0
 
RaymondAuthor Commented:
Did you test it ?
In Win2000, my application still show on Application tab of task manager.

MW
0
 
MadYugoslavCommented:
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
 
ViestursCommented:
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
 
jizhangCommented:
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
 
AxterCommented:
jizhang,
The questioner is trying to do this to the current program, not one he/she is trying to launch.
0
 
MoondancerCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.