run a vb application as a service

Posted on 2006-05-30
Last Modified: 2010-04-30
I created an .exe file using a vb program. can anyone tell how to schedule this as a service. I am using windows server 2003 R2. I want this vb program to run once a day. Is there any other way to do this other than scheduling this a service.


Question by:cognos79
    LVL 2

    Expert Comment

    I don't think you need to run it as a service.
    Windows Task scheduler can run a program without it being a service, providing your program requires no user inputs.
    You can find it in Control Panel - scheduled tasks.
    You can schedule daily, selected days of week, and even repeat every xx miutes / hours etc.

    If the program needs no network access, it is probably OK to run under system account (the default). If network access required, you will need to supply details of a user account.

    If you really want to run as a service (a program that remains running) you could use AlwaysUp (shareware) - see
    I have used this for software that is not a service, and must re-start reliably after an unattended re-boot.

    LVL 3

    Author Comment

    hey dcp002,

        i used windows task scheduler. I dont think its working correctly for me. I have an .exe program which sends out email. its a simple program. I scheduled it to send email every 2 mins. this is just for testing purpose. But its not sending email as intended. It only sends out email once at the scheduled time and  after every 2 mins it should send email again. its not doing that. do you have any ideas.

    when i just click the .exe it sending out email. I am also pasting here the code i used.

     Const cdoSendUsingMethod = _
        Const cdoSendUsingPort = 2
        Const cdoSMTPServer = _
        Const cdoSMTPServerPort = _
        Const cdoSMTPConnectionTimeout = _
        Const cdoSMTPAuthenticate = _
        Const cdoBasic = 1
        Const cdoSendUserName = _
        Const cdoSendPassword = _
        Dim objConfig  ' As CDO.Configuration
        Dim objMessage ' As CDO.Message
        Dim Fields     ' As ADODB.Fields
        ' Get a handle on the config object and it's fields
        Set objConfig = CreateObject("CDO.Configuration")
        Set Fields = objConfig.Fields
        ' Set config fields we care about
        With Fields
            .Item(cdoSendUsingMethod) = cdoSendUsingPort
            .Item(cdoSMTPServer) = ServerName
            .Item(cdoSMTPServerPort) = 25
            .Item(cdoSMTPConnectionTimeout) = 10
            .Item(cdoSMTPAuthenticate) = cdoBasic
            .Item(cdoSendUserName) = UserName
            .Item(cdoSendPassword) = Password    
        End With
        Dim filepath
        filepath = "E:/WebFiles/" & FileName
        Set objMessage = CreateObject("CDO.Message")
        Set objMessage.Configuration = objConfig
        With objMessage
            .To = ""
            .From = ""
            .Subject = "testing"
            .TextBody = "this is test version"
            '.AddAttachment filepath
        End With
        Set Fields = Nothing
        Set objMessage = Nothing
        Set objConfig = Nothing
    LVL 3

    Author Comment

    one thing i noticed is when i schedule the job on my local computer its working only if i close the application after it runs. when it runs the .exe file its opening up the vb form and i have to close it. then only its running the job after 2 minutes. if i dont close it its not running again.

    But on the server i dont see the vb form popping up to close it.

    LVL 3

    Author Comment

    do i have to use a kill statement in the program.
    LVL 2

    Accepted Solution

    You simply need to put an "END" statement at the end of the program so it closes once it has done its job.
    LVL 3

    Author Comment

    cool. it worked. you rock.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Suggested Solutions

    When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now