• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1084
  • Last Modified:

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.

Thanks!!!
0
potpourrigroup
Asked:
potpourrigroup
  • 2
  • 2
  • 2
1 Solution
 
broadbentCommented:
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
etc

so going back to your code in the vb app, add the following to stop your timer.
myControl.ExecuteCommand(201)

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





0
 
doobdaveCommented:
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.

David
0
 
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.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now