VB.NET | Convert EXE to Service

I have a vb.net 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.

Who is Participating?
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.

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.

potpourrigroupAuthor Commented:
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.
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

potpourrigroupAuthor Commented:
Oops... Meant it WOULD be OK.
And I can't find how to "interact with the desktop"
I have VS 2003, and 2005 Express
As I meantioned above, go to SERVICES (control panel>administrative tools), "log On" tab, and it's there
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.