run a vb application as a service

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.


Who is Participating?
dcp002Connect With a Mentor Commented:
You simply need to put an "END" statement at the end of the program so it closes once it has done its job.
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.

cognos79Author Commented:
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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

cognos79Author Commented:
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.

cognos79Author Commented:
do i have to use a kill statement in the program.
cognos79Author Commented:
cool. it worked. you rock.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.