We help IT Professionals succeed at work.

How to install windows service on my local computer

Junior_Developer
on
Medium Priority
216 Views
Last Modified: 2010-04-23
Hi Experts,
Can you please tell me How to install windows service on my local computer?
i was trying to install it using projectInstaller
i dont know why it is not working...
I also created same exact application as a windows application to see if there is a problem in the application but the application is running fine and does what i need it to do... in short.

For windows service i have created following all the work is done in Timer1_Elapsed function


Imports System.ServiceProcess
Imports System.IO
Imports System.IO.FileSystemEventArgs
Imports System.Configuration

Protected Overrides Sub OnStart(ByVal args() As String)
          Timer1.Start()

End Sub

Protected Overrides Sub OnStop()
        ' Add code here to perform any tear-down necessary to stop your service.
        Timer1.Stop()

End Sub

Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
        Dim strFilesPath As String
        strFilesPath = ConfigurationSettings.AppSettings.Get("FilesPath")
       
      Dim oldFileName As String
        Dim newFileName As String

' HERE I HAVE CODE TO GET MY oldFilename and NewFilename

        For Each fl In fls
             Rename(strPath + oldFileName, strPath + newFileName)
        Next
    End Sub
End Class
Comment
Watch Question

CERTIFIED EXPERT

Commented:
don't you think you should call Timer1_Elapsed from OnStart event of your service?
CERTIFIED EXPERT

Commented:
what does Timer1.Start() do?

Author

Commented:
Well please guide me...
all the functionality that need to be done is in Timer1_Elapsed.
Timer1.start() will just starts the timer and i am thinking after that timer1_elapsed is called so i put my functionality in elapsed please let me know if you think i need to change it.
Commented:
timer1 should be at first enable=false then with starting ur service it should change to true and with stop change to false
Protected Overrides Sub OnStart(ByVal args() As String)
          Timer1.enable=true

End Sub

Protected Overrides Sub OnStop()
        ' Add code here to perform any tear-down necessary to stop your service.
        Timer1.enable=false

End Sub

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

Ask the Experts

Author

Commented:
The functionality that i am using where should i write it after adding timer1.enable = true in onstart and timer1.enable = false in onStop.
Do i still keep it in timer_elapsed() ?

Commented:
no, in windows service you have two sub routine one is Onstart and the other is Onstop you should write your code there,  by the way, if your window service call any local file , you should give it full path of your local file or put that file in system32 unless your service will fail. the way you could be able to know the window service error is write in eventlog. in this way you could be able to understand its error too.
good luck
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.