We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

VB.NET | Convert EXE to Service

potpourrigroup
on
Medium Priority
1,142 Views
Last Modified: 2012-08-14
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!!!
Comment
Watch Question

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.





Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

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

Author

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.

Author

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

Commented:
As I meantioned above, go to SERVICES (control panel>administrative tools), "log On" tab, and it's there
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.