How to change a VB 2005 application to a service?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 12 of 12

Thread: How to change a VB 2005 application to a service?

  1. #1
    Join Date
    Apr 2008
    Posts
    7

    How to change a VB 2005 application to a service?

    Hi,

    I'd like to change my VB application into a service (Visual Studio 2005).

    I had done this one before but I am having difficulties this time. The specific error that I am getting is 'Sub Main' was not found in 'myProgram.Form1'.

    I deleted the form while changing it to a service...

    When I double-click the error I see a dialog which says "This project does not have a valid Sub Main(). You must add Shared Sub Main() End Sub to a class or module."

    I can not find a Main() in my original program.

    Here are the notes I recorded from the first time I changed an application to a service. Perhaps something specific in these steps is causing the problem?

    - In project explorer double click the project name and change it to a service (application type)

    - Project -> Add Class -> Windows Service (name Service1.vb)

    - Double click the Service1.vb file in Solution Explorer

    - Delete the "datagrid" component from the designer

    - Left click anywhere on the designer

    - Right click on the grey background of the designer and choose "Add Installer"

    - Set ServiceInstaller1 starttype to Automatic

    - Set ServiceInstaller1 service name

    - Select ServiceProcessInstaller1 and change the property "Account" to "LocalService"

    - File -> Add New -> Other Project Types -> Setup and Deployment -> Setup Project

    - Right click on Setup1 -> Add -> Project Output -> Primary Output -> Ok

    - Right click on Setup1 -> View -> Custom Actions

    - Right click on Install -> Add Custom Action -> Look in: Application Folder -> Primary output from project

    - Repeat the previous step for Commit, Rollback, and Uninstall

    - Build -> Clean -> Rebuild Setup1

    -> Now right click on Setup1 and choose "Install"


    Thanks for any assistance.

  2. #2
    Join Date
    May 2004
    Location
    Duluth MN
    Posts
    353
    On the application property dialog (where you changed the type to Windows Service) there is a check box, Enable application framework. This neds to be unchecked if you do not have a form in your solution. You will also need to create a Sub called Main as your startup object. Here you will initialize any variables you need and call your procedure. It acts as the entry point for your service, Like the Load event of a startup form.

    ...joe

  3. #3
    Join Date
    Apr 2008
    Posts
    7
    Thanks Joe. Somehow I was able to change the "Startup Object" to a sub that I created in my Service1.vb file in the service that I had working in the past.

    This new service only gives me the option of "Main," after I uncheck "use application framework." Doing that did prevent the Form errors from appearing but I am not sure how to properly structure a Main statement.

    Regards

    techphets

  4. #4
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Main is not a statement. It is a Sub.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  5. #5
    Join Date
    May 2004
    Location
    Duluth MN
    Posts
    353
    Quote Originally Posted by techphets
    Thanks Joe. Somehow I was able to change the "Startup Object" to a sub that I created in my Service1.vb file in the service that I had working in the past.

    This new service only gives me the option of "Main," after I uncheck "use application framework." Doing that did prevent the Form errors from appearing but I am not sure how to properly structure a Main statement.

    Regards

    techphets
    As Hack says, Main is just a sub:

    Code:
    Public Sub Main()
        'Some code to initialize variables and call you startup procedure
    End Sub
    Your application/service always needs an entry point so the application knows what to do when it's called. In most windows apps this would be what you place in the startup form's load event. If you don't have a form or you need to do some things before loading it you use a Main() sub.
    Last edited by joewmaki; 04-07-2008 at 07:50 AM.

    ...joe

  6. #6
    Join Date
    Apr 2008
    Posts
    7
    Ahh yes, I meant Sub. I'll give Main another try. How can I change the "Startup Object" to something other than Main?

  7. #7
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Going into Project/Properties
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  8. #8
    Join Date
    Apr 2008
    Posts
    7
    My only option is Main.

  9. #9
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Ok, but is it something that you create rather than something that is created for you.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  10. #10
    Join Date
    Mar 2005
    Location
    Los Angeles, Calif. AKA: Gangsta Yoda™
    Posts
    455
    A service does not and should not contain any forms or other GUI interactions.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer code questions via PMs.
    Microsoft MVP 2006-2009
    Office Development FAQ (VBA, VB6, VB.NET, C#)
    Software Engineer MCP (VB6 & .NET)
    Reps & Rating PostsVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6Outlook Global Address List

  11. #11
    Join Date
    Apr 2008
    Posts
    7
    Thanks Rob,

    That's why I'm trying to remove the forms from this application- so it can be used as a service.

    Hack,

    There must be some way I can create it because I have a startup object set to a class that I wrote in the project that does work as a service.

  12. #12
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Can't you just add a module to your project, and do something like
    Code:
    Module Module1
        Sub Main()
            'put your code here
        End Sub
    End Module
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Similar Threads

  1. Using Java 6SE to query a web service
    By (MC3)RaVeN in forum Java
    Replies: 0
    Last Post: 03-02-2007, 09:30 AM
  2. Replies: 0
    Last Post: 11-25-2002, 11:09 PM
  3. Windows Service with VB .Net
    By Bryce Ostenson in forum .NET
    Replies: 2
    Last Post: 04-18-2002, 10:08 PM
  4. VB Application - SoS
    By Harsha in forum VB Classic
    Replies: 1
    Last Post: 01-29-2001, 12:11 PM
  5. Capturing mouse clicks outside VB Application
    By Sunil in forum VB Classic
    Replies: 0
    Last Post: 07-28-2000, 08:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center