Solved

windows service in asp.net

Posted on 2013-12-09
3
273 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Loop not working 29 48
SQL Login 17 41
Write to file when application closes (by logoff) - VB.NET 1 21
VB.NET Repostiory Pattern 7 17
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

27 Experts available now in Live!

Get 1:1 Help Now