VB.NET | Convert EXE to Service

Posted on 2006-03-30
Last Modified: 2012-08-14
I have a exe program that stays minimized all day and moves files every 15 minutes. Would it be more efficient converting it to a Windows Service, and if so, how do I go about it? It is currently a Windows Form that uses the Timer fuction in Visual Studio.

Question by:potpourrigroup
    LVL 4

    Accepted Solution

    The easiest way is to start a new project using the Windows Service template, and then cut and paste your exe project into it or vice versa. What I then do is to copy the application from C:\Windows\Microsoft.NET\Framework\v1.1.4322 (?) \InstallUtil.exe to my \bin folder and use run InstallUtil myapp.exe. I do this through another application which includes the following code:-

    Dim Prcs() as Process = Process.GetProcessesByName("mylog")
    if UBound(Prcs) < 0 then
     Dim prc as new Process
     prc.StartInfo.FileName = MyPath & "\InstallUtil.Exe"
     prc.StartInfo.Arguments = "myapp.exe"
     prc.Start ()
    End if
    Dim myControl as New System.ServiceProcess.ServiceController("mylog")
     If myControl.Status = ServiceProcess.ServiceControllerStatus.Stopped then mtControl.Start()

    To start or stop the timer, you need to use OnCustomCommand(Byval command as integer)
    where command is an integer number. I've tried 1 and 2 and these don't work. 201 and 202 etc do, but I haven't worked out the limits.
    Then do
    Select Case Command
    Case 201: timer.stop

    so going back to your code in the vb app, add the following to stop your timer.

    That done, I haven't been able to get my service to write an entry to a file.

    LVL 8

    Expert Comment

    potpourrigroup / broadbent,

    You may also need to set the service to "interact with the desktop", by going to its properties under SERVICES, and going to the "Log On" tab.


    Author Comment

    I have Visual Studio Express and I don't see the Windows Service template. Can I download it or do I need the "real" version of studio? This is a company project so purchasing VS wouldn't be OK if I really need it. I'm sure I could do a lot more with the full version anyway.

    Author Comment

    Oops... Meant it WOULD be OK.
    LVL 4

    Expert Comment

    And I can't find how to "interact with the desktop"
    I have VS 2003, and 2005 Express
    LVL 8

    Expert Comment

    As I meantioned above, go to SERVICES (control panel>administrative tools), "log On" tab, and it's there

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    759 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

    10 Experts available now in Live!

    Get 1:1 Help Now