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?
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.
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.
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.
Related
We have an internally developed VB.Net Windows Forms Application that handles all our Auto-Updating for our other software applications. Whenever I run the application in Windows 10, the application starts under the "Background Processes" section of the Task Manager. The only way I can get it to run in the foreground is to run it as an Administrator even though I'm an Admin on the VM and my UAC settings are turned all the way down. This doesn't happen in Windows 7 or 8 so I'm wondering if there's something I'm doing wrong or something about Windows 10 that's changed where it has to be run as an Admin. Our other applications don't seem to have this issue, it's just specifically this one application for some reason but I can't seem to figure out what's different.
So I put some more error handling in and it sounds like #xfx was onto the right idea. The application is erring when it starts up because it can't register the URL of the WCF service so it never got to the point where it was displaying the form. Once I manually registered the URL of the WCF service and ran the application as an Admin, it displayed and worked like normal.
This is because of the way the project has been configured in Visual Studio.
Here's how to create an application that behaves like a background process:
In the Project settings dialog, disable the Enable application framework option
Next, change the Startup object to Sub Main
Finally, add a Module to the project and add the following code:
Module Module1
Sub Main()
Application.Run()
End Sub
End Module
If you run the application (not from within the IDE, but directly) it will behave just like the one you describe.
The application will remain as a background process as long as it doesn't display a Form. As soon as one is displayed, you will see that Task Manager moves the process from the Background processes list to the Apps list.
To test this, just change the code in the Module for this version:
Imports System.Threading
Module Module1
Sub Main()
Dim tmp As New Thread(Sub()
Thread.Sleep(3000)
Using f As New Form1()
f.ShowDialog()
End Using
End Sub)
tmp.Start()
Application.Run()
End Sub
End Module
The application will start as a background process and 3 seconds later will display form, becoming a foreground process.
I have a vb.net Windows Forms application using Visual Studio 2010. At design time my buttons look like this:
at run time they seem to revert to a Windows classic style:
It only happens for this project which I took over from a developer who left. I want them to look like they do at design time. I'm stumped. Any ideas?
If the app starts from a Sub Main rather than a main form (See Project -> Properties -> StartUp Object) it might be missing this:
Public Sub Main()
' probably missing:
Application.EnableVisualStyles()
Application.Run(New Form1)
End Sub
When starting from a Main sub, be sure that EnableVisualStyles() is invoked very early in the procedure before any UI Objects are created.
If it starts from a main form, go to the same Project properties and be sure that both Enable application framework and Enable XP Visual Styles are checked.
If it still doesnt work, turn on Show All Files in Solution Explorer and open Application.myApp under My Project. Make sure this setting is true:
<EnableVisualStyles>true</EnableVisualStyles>
This file/setting should be managed by VS, so if it is not being updated to match the IDE, you might have other issues.
I'm really struggling to find out how to dynamically load a form when starting a VB.NET winforms application in VS2010.
Looking at existing answers such as this: Programmatically change the startup form on application launch?
Has not helped. I do not have a main method (that I can see) in my winforms project and when I go into the project properties I can only select a start-up form. But I have one of two forms to display on start-up depending on the user accessing the application.
I tried to set a loading form up which, in it's load event would call .Show() on the correct loading form after it had determined it and then the loading form would close itself down, but doing this led to both forms being closed.
Below are steps for VS2010 VB.NET Winforms select startup form programmatically.
1 : Go to My project from Solution Explorer
2 : Click on Application Tab--->Uncheck Enable application Framework
3 : Then Inside module create Sub like this
Public Sub Main()
MsgBox("called Main") 'This is testing
Login.Show() 'Set your start up form here
End Sub
4 : Again My Project--->Application Tab--->Startup Object--->Sub Main
5 : Thats it, It will give you message box and will show Login form.
Hope It will help you.
Thanks
Mahesh
Nevermind. I found in the properties a button to generate the MyApplication class in which I can access the startup event.
Another option is to use an MDI form. When it loads you can determine which child form to display.
Using Sub Main is the way I have done this forever but for some reason, MS has decided to make the norm, difficult. To use the Sub Main way, create a "Module" if you dont already have one. Put this code in there:
Sub Main()
Stop
End Sub
Now, in your project properties, assuming your are doing a standard WinForms application, on the "Application" tab, uncheck the "Enable Application Framework". This will allow you to see (and select) "Sub Main" in the "Startup Object" drop-down.
I've been given a windows form application written in VB. For some reasons I will need to execute the second class before the form application in the first class. The form class has to be the first class in the file. I can't simply inherit the second class and call the functions, because it has already used up the only allowable inheritance. I did some research and found there is something called main procedure that determines which codes executes first? It is automatically generated for any windows form application, but I simply can't find that file. Any thoughts on that? or any other ways that I do this?
Follow Start VB.NET GUI app using Sub Main or form startup object? for better alternatives.
But if you really need to start with Main(), follow these steps.
Open application settings.
Uncheck "Enable application framework"
Set startup object to "Sub Main"
Then add a new source file (.vb) and include Main() in it
Module MainModule
Sub Main()
'Your code here
End Sub
End Module
Is there any reason to start a GUI program (application for Windows) written in VB.NET in the Sub Main of a module rather than directly in a form?
EDIT: The program won't take any command line parameters and it will be executed as a GUI program always.
The primary reason for using Main() in VB .NET 1.x was for adding code that needed to run before any forms were loaded. For example, you might want to detect whether an instance of your Windows Forms app was already loaded. Or you might want to intercept any unhandled exception for the AppDomain:
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf MyExceptionFilter
But the next version of VB and Visual Studio 2005 introduced a new Application model that made Main() unnecessary in most scenarios. You can now intercept the My.Application.Startup event to add code that needs to run before any forms are loaded.
Note that the code for the Startup event handler is stored in the ApplicationEvents.vb file, which is hidden by default.
You can do it either way, but you should really only keep code in the form that is directly related to the operations and user interface elements on that form. Application startup code isn't related to UI, normally concerned with splash screens, checking network connectivity, verifying a single instance only, setting up user configuration settings, and so on.
After the above items (or the appropriate initialization code for your app) are complete, Sub Main can create an instance of the main form, then show it so the user can begin interacting with your application.
This separates startup code from your form code. Later, when you're maintaining the application, you'll be glad you separated the two.
Yes, and I have done it a few times.
One reason is, that if your app is COM EXE (speaking now from a VB6 point of view) then you want to be able to detect in what context the EXE is being called (being launched or being spoken to by some other app).
For example:
Sub Main()
If App.StartMode = vbSModeAutomation Then
...
Else
...
End If
End Sub
Another is if you want your app to be able to handle any command line parameters.
For example:
Sub Main()
If App.PrevInstance Then End
If InStr(Command, "/s") > 0 Then
Form1.Show
ElseIf InStr(Command, "/p") > 0 Then
LoadPicture ("c:\windows\Zapotec.bmp")
End If
End Sub
(from one of my attempts to make a screen saver)
No, if you always want to show that form.
Yes, if you sometimes want to use your app without GUI, just using command line.
Yes, if I want to display different forms depending on some parameter (in a file, on a remote server, etc.).