Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

windows service in asp.net

Posted on 2013-12-09
3
Medium Priority
?
281 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 27

Accepted Solution

by:
Chinmay Patel earned 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

604 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