Solved

windows service in asp.net

Posted on 2013-12-09
3
270 Views
Last Modified: 2014-01-06
hi
i need to make a system in .Net to access the service SDRSVC  (Windows backup)
and to see when was the last backup done or when this service was running last time
or if there is any failure

i try this code
  Dim services As ServiceController() = ServiceController.GetServices()

            Response.Write("List of running services : <BR>")
            For Each service As ServiceController In services


                If service.ServiceName = "SDRSVC" Then
                    Response.Write(String.Format(" Service Name: {0} , status {1} <BR>", service.ServiceName, service.Status.ToString()))

                End If


            Next

Open in new window


but i dont know how to access the properties of when it was last running ...etc

Please help
0
Comment
Question by:Kamal Khaleefa
3 Comments
 
LVL 27

Accepted Solution

by:
Chinmay Patel earned 500 total points
ID: 39706441
There is no way to get this information from ServiceController. I recommend that you follow this code:

Basically you will loop through event log entries 'cause that's where you can accurately find information on a properly developed Services' whereabouts.

public List<Hashtable> GetEventEntryByEvent(
            ref string logName, ref string machineName, 
            ref string source)
        {
            try
            {
                //Create our list
                List<Hashtable> events = new List<Hashtable>();

                //Connect to the EventLog of the specified machine
                EventLog log = new EventLog(logName, machineName);

                //Now we want to loop through each entry
                foreach (EventLogEntry entry in log.Entries)
                {
                    //If we run across one with the right entry source
                    //  we create a new Hashtable
                    //  then we add the Message,Source, and TimeWritten values
                    //  from that entry
                    if (entry.Source == source)
                    {
                        Hashtable entryInfo = new Hashtable();

                        entryInfo.Add("Message", entry.Message);
                        entryInfo.Add("InstanceId", entry.InstanceId);
                        entryInfo.Add("Source", entry.Source);
                        entryInfo.Add("TimeWritten", entry.TimeWritten);
                        // You can also replace TimeWritten with TimeGenerated
                        //Add this new Hashtable to our list
                        events.Add(entryInfo);

                        entryInfo = null;
                    }
                }
                //Return the results and process these results to see when it was last time started
                return events;
            }
            catch (Exception ex)
            {
                //Display an error message
                return null;
            }
        }

Open in new window


Source: http://stackoverflow.com/questions/1928933/c-sharp-get-date-time-a-windows-service-started
0
 
LVL 16

Author Closing Comment

by:Kamal Khaleefa
ID: 39758869
Thank you it give a hint to workaround
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now