DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 12 of 12

Thread: window services

  1. #1
    Join Date
    Mar 2004
    Posts
    3

    window services

    hi , every body

    i am working on window services. i need to update client database with the changes at server, i have done that.
    but in case the service fails i want the user to know about it,
    want to display a message box. it message box is not in the name space of window services, how can i do this ?

    any help is welcome

    thanx in advnce

    gouthamdon

  2. #2
    Join Date
    Mar 2004
    Posts
    23
    You can't display message boxes within a service. It will end up in the Event Log. You need to determine another method of communication to your user. We have services that require notifications upon errors and we generate email messages to a tech support address (internally). Another option is you could utilize net send messaging but this will need to rely on the Alerter and Messenger services to be running. Personally, I'd opt for the email myself.

  3. #3
    Join Date
    Apr 2004
    Posts
    19
    In addition to your service running, also have a client app than runs in the desktop tray -- this can create desktop notifications -- Kind of like Outlook telling you that you have new email.

    You can:
    1) Keep asking the service if there's anything to report
    2) Display a message on failure

  4. #4
    Join Date
    Dec 2003
    Posts
    37
    I have a question about Windows Services.

    I have VB6 applications. One was long-running application which using timer(s) to periodical checking to see if a flag was set. If the flag was found it will deleted the flag and trigger another VB6 application with "Shell" to do some calculation.

    Now I need to re-write or convert the application(s), at least the long-running one, to Service application.

    My question is can I still use "Shell" to call my second calculation program in the first re-written one? (Or I also have to re-write my calculation application to VS.net?) if yes any restrication(s) for the second one?

    Thanks for your help.

    PS: Any books or articles I can refer to for developing in Service Application with VS.net?

  5. #5
    Join Date
    Apr 2004
    Posts
    19

    Shell in Services and recommended resources

    Yes, you can run a shell command from a windows service. Be careful if you have the service run as System though -- if someone hacks/changes the shell resource it will have root access. Do a search on the "Process" object in MSDN and that's what you should use to excecute something.

    As for Service resources -- this book was great (in C#) -- Amazon C# 2nd Edition

  6. #6
    Join Date
    Dec 2003
    Posts
    37
    I searched on "Process" on MSDN and had following code on my Service Application:

    Imports System.ServiceProcess

    Public Class MyNewService
    Inherits System.ServiceProcess.ServiceBase

    Protected Overrides Sub OnStart(ByVal args() As String)

    EventLog1.WriteEntry("In OnStart")
    Timer2.Enabled = True

    End Sub

    Protected Overrides Sub OnStop()

    EventLog1.WriteEntry("In OnStop.")

    End Sub

    Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed

    Dim myProcess As New Process

    Timer1.Enabled = False

    myProcess.StartInfo.FileName = "Notepad.exe"
    myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal '.Maximized
    myProcess.Start()

    Timer2.Enabled = True

    End Sub

    Private Sub Timer2_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer2.Elapsed

    If Len(Dir("C:\temp\TimerFlag.ok")) > 0 Then
    Timer2.Enabled = False
    Kill("C:\temp\TimerFlag.ok")
    Timer1.Enabled = True
    End If

    End Sub

    End Class

    After installation it and starting it from "Services" on Administrative Tools, I set flag file "TimerFlag.txt". The flag file was deleted but I caould see NotePad.exe showed on windows desktop. I checked "Processes" tab on Windows Task Manager and saw NotePad.exe on the running list however it was not sgow on "Applications" tab. How can I bring notepad.exe on the windows screen?

    (I have Windows 2000 and Visual Studion.net 2003)

    Thanks for your insight.

  7. #7
    Join Date
    Apr 2004
    Posts
    19
    Windows Services cannot access the desktop. This is because you could have 5 users logged into that computer and the service wouldn't know which desktop to put it on.

    I think you were doing this as a test rather than actually needing to show Notepad. Debugging Services is hard -- you'll need to use log files rather than messages.

    If I'm wrong on why you need Notepad to show, let me know.

  8. #8
    Join Date
    Dec 2003
    Posts
    37
    Yes you are right.

    I am just doing some testing to run a windows application, Notepad.exe, with a call from service application.

    My purpose is eventually to call (Shell or Process) my "Calculation" program that I mentioned on previous post (We currently have two vb6 applications, let’s say one is called “Auto.exe” and the other called “Calculation.exe” ran on server. Auto.exe is a long-running program which had Timers to periodical to search a flag file. If it finds the flag it will delete it and calls “Calculation.exe” to do financal calc.)

    Now I was required to re-write programs, at lest long-running program, on a server to Service Applications.

    What I wanted to do here is that with as less work as possible to reach the requirement, of course also with as less time as possible.
    I want to re-write Auto.exe with VS.net as service application and modified Calc (It was an Access database application with DAO) with VB6 by replaying those windows features such as displaying error on screen, displaying processing log with writing them into an Event log file

    Can I reach my goal here?

    Thanks lot for your help!

  9. #9
    Join Date
    Apr 2004
    Posts
    19
    Yes, you can...

    1) Write Auto.exe as a service application. It will periodically search a file, setting an internal bool. Auto.exe also listens to a windows port, and reports the status on the bool

    2) Write a new calc program. The program should start when the user logs in, and run minimized in the system tray. It will periodically ask the Auto service on its port the status of the bool.


    note --- I also think the service can perform the calculations, and the calc program just asks the service if there are messages to display.

  10. #10
    Join Date
    Dec 2003
    Posts
    37
    I really appreciated your help!!!

  11. #11
    Join Date
    Dec 2003
    Posts
    37
    I have a question: How to terminate a process?

    I re-wrote my Calc application, VMPE4SRVAPP.exe, by removing all Windows Interface controls and leaving only functions that are to create an Access database and to load data into it.

    I also added a Process Control, myProcess, onto my Service application and have following code:

    myProcess.StartInfo.FileName= "C:\VMPE4SRVAPP\VMPE4SRVAPP.exe"
    myProcess.StartInfo.Arguments = "vm3retail"
    myProcess.StartInfo.WorkingDirectory = "C:\VMPE4SRVAPP"
    myProcess.StartInfo.RedirectStandardOutput = False 'True
    myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized '.Maximized
    myProcess.Start()

    I Installed the service. When I started it, I could see (from widnows explorer) a MDB file was generated and its size indicated the data was loaded. I also saw VMPE4SRVAPP.exe was displayed on Processes tab of Windows Task Manager. However the process stayed on the tab forever so that could not access the MDB file. When I tried to Open the MDB file, I got "Access denied... It is already being in use". When I tried to copy the MDB I got "Sharing vialation".

    Does the above indicat that the process is strill running? How to terninate the process after my VMPE4SRVAPP job was done?

    (After re-booting my machine, I can open the MDB)

    Thanks for your advice.

  12. #12
    Join Date
    Dec 2003
    Posts
    37
    One correction: Instead of "add a Process Control, myProcess, onto my Service application and have following code: ", I actually used following code in Timer_Elapsed event handler

    Dim myProcess As New Process

    Process1.StartInfo.FileName = "C:\VMPE4SRVAPP\VMPE4SRVAPP.exe"
    Process1.StartInfo.Arguments = "vm3retail"
    Process1.StartInfo.WorkingDirectory = "C:\VMPE4SRVAPP"
    Process1.StartInfo.RedirectStandardOutput = False 'True
    Process1.StartInfo.WindowStyle = ProcessWindowStyle.Minimized
    Process1.Start()

    Sorry for the oversight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center