3

I'm making a VB.net program via a text file and I'm compiling it using vbc.exe via command line. I'm trying to get just a simple program to run in the background of my computer. Problem is, it displays the annoying console window. How do I get nothing to show? No form, no console?

Freesnöw
  • 30,619
  • 30
  • 89
  • 138
  • @LarsTech Yes, kind of, I really don't need it to be one. It's just a small light weight program for personal use. Nothing that needs to be installed as a service. I would also run it myself. – Freesnöw Nov 17 '11 at 14:02
  • But if there's no Form and no Console, how would you interact with it? Close it? Do something with it? I think we need context here for what the program does. – LarsTech Nov 17 '11 at 14:06
  • @LarsTech The program itself is handled through key presses. It uses key hooks to read what I press and based on what keys I press (e.g. SHIFT + TAB) to do something. – Freesnöw Nov 17 '11 at 14:08

3 Answers3

9

Just use windows forms application don't load the form at all! Just go in project properties and uncheck enable application framework. Now, in the startup object dropdown, select "sub main". Add a module to the project and put a Public Sub Main() in it. You do all the stuff in main() and don't load form at all.

Conrad Frix
  • 51,984
  • 12
  • 96
  • 155
MemoryVandal
  • 191
  • 6
8

I think you need a form of some kind to keep the message loop going.

Maybe a NotifyIcon type program. It would keep it away from the task bar and desktop areas.

And then customize the NotifyIcon to "Only Show Notifications" from the "Customize" menu for your icon using Windows.

LarsTech
  • 80,625
  • 14
  • 153
  • 225
  • 1
    Lars is correct - if you don't want to use a windows service then you shouldn't be running a program in the background without the user being able to 'see it' - this will also give them the option to Exit the application without having to resort to task manager. – Matt Wilko Nov 17 '11 at 16:03
5

1) Add a module in your project, and create Sub Main
2) Write whatever you want in Sub Main,and MAKE SURE you end it with this statement:

Application.Run()

3) Open properties of your project and choose "Sub Main" as startup object

So , your application will have NO INTERFACE (NO FORM / NOT CONSOLE APPLICATION) and will run from Sub Main(), in addition it will NOT TERMINATE once all the code in Sub Main has executed.Your program will run like a NORMAL windows form application, and will only exit when you want.

Jet
  • 528
  • 6
  • 17
  • (Hmm... Some people downvote another's answers and upvote themselves...) – Jet Jul 31 '13 at 09:57
  • It worked!, i've just created a system.timers.timer() in Sub Main and started it... finally just called Application.Run(), and it behaves as a service. Using a while True bucle consumed 25% of CPU. Thank you! – ZeroWorks Feb 26 '15 at 09:59
  • @ZeroWorks While-true is a bad practice. Use Sleep() function instead. And feel free to upvote if it helped ;) – Jet May 01 '15 at 23:10
  • yes while-true consumed 25% of CPU and I used another approach, also I upvoted but it seems somebody downvoted this answer. Thank you! – ZeroWorks May 03 '15 at 09:12
  • I upvoted both MemoryVandal and Jet answers because in this one you didn't tell about "uncheck enable application framework". Thanks to both for the answers, it helps me a lot. – LogoS May 23 '16 at 12:53