Ruba
Ruba

Reputation: 837

Running program in background


I've a mini project I have to do in "Information System Security" subject, the idea is I have to run a program in background when the user is browsing the net and perform some actions.
I've made some search and I think i may need to write a windows service program. Is that correct? or what should I do to make my program run in background?
please any help.
Thanks.

Upvotes: 0

Views: 5498

Answers (3)

Luis Rodriguez
Luis Rodriguez

Reputation: 41

To make your program run in background you can use event Shown of your form.

put this into Shown event:

    private void Form1_Shown(object sender, EventArgs e)
    {
        this.WindowState = FormWindowState.Minimized;
        this.Hide();
    }

Upvotes: 1

caesay
caesay

Reputation: 17271

Just create a Winforms application, delete the form, and put your code in the Main() method in Program.cs. Keep it alive as long as you need, and run whatever background tasks you need too.

Upvotes: 0

maja
maja

Reputation: 18034

If you don't want to write a service-Program you can hide your program-windows after the program started with

ShowWindow(HWND,int);

In order to get the Window-Handler to your own Window, you can use for example

HWND explorer=::FindWindow(NULL,"explorer.exe");

or

HWND h = ::GetTopWindow(0);
while ( h )
{    if(IsWindowVisible(h)==1 && /*check if it's your Window*/)
     {   ShowWindow(h,0);//will hide Window
         break;
     }
     h = ::GetNextWindow( h , GW_HWNDNEXT);
}

You will have to

#include <winuser.h>

to use this functions

Upvotes: 0

Related Questions