Rootel Rootel - 2 months ago 5x Question

VB.NET Background Application

I need to create one application that runs in the background.

I tried to hide it on startup:

It didn't work out, tho.

My question now is how do I make a VB.NET application that runs as a administrator and is hidden without the user knowing about it.

Thanks for your time.


I assume you're using Windows Forms since you said "I tried to hide it on startup, Me.Hide. Didn't work out, tho."

It's pretty simple, actually. Don't show the form until you want to. To do this, I'd disable the Enable Application Framework option in the project properties. (See, the option I mentioned is there somewhere.).

Then, create a new class (or you can use a module) in your project and name it "Program". The name isn't really important, but by convention it's usually "Program".

Create the famous "Main" procedure within this class. There are a few available signatures for this function.

  1. The simplest is as simple as: Public Shared Sub Main()
  2. Alternatively, you can receive command line arguments: Public Shared Sub Main(ByVal args() As String)
  3. Repeat 1, but as a function returning a 32-bit signed-integer.
  4. Repeat 2, but as a function returning a 32-bit signed-integer.

The point of returning an integer on the end of the 'Main' functions is to return an exit code specifying if everything went "OK". You generally return 0 if everything worked and an error-code or something to specify an error occurred.

Set the project's "Startup Object" to your new class.

Finally, if you ever want to show a form simply instantiate an object whose type is your form and show it.

Dim form As New Form1() form.Show()

And as always, dispose the form when you're done with it.