?
Solved

Need to have IF statement also only go if the time is after or before 2PM

Posted on 2005-04-04
3
Medium Priority
?
237 Views
Last Modified: 2010-04-16
What I need to do is also have the IF statement work on a time as well. For example if it is after 2 or before 2pm. This way there is no dupicated message being sent out

using System;
using System.Management;
using System.Management.Instrumentation;
using System.Xml;
using System.IO;
using System.Collections;
using Microsoft.Win32;
using QTI.Monitor.Configuration;

namespace Q.M.T
{
      /// <summary>
      /// Tell the central server the date of when the Customer  
      /// last rebooted the PC.  
      /// </summary>
      public class TaskPCLastReboot : TaskInterface
      {
            /// <SUMMARY> </SUMMARY>
            public void DoTask(XmlNode xmlNode, ref int iSeverityLevel,
                  ref String[] sValues, ref String[] sDetails)

            {
                  //system date need to see if last reboot was today or yesterday after
                  //client last ran checks.
                  System.DateTime today = System.DateTime.Today;
                  System.DateTime daybefore = today.AddDays(-1);
      
                  try
                  {
                        //This is the actual search to get the restart date from the
                        //operating system
                        string ConfigNamespace = @"\\.\root\cimv2";
                        string query = "select * from Win32_OperatingSystem";

                        ManagementObjectSearcher searcher = new
                              ManagementObjectSearcher( ConfigNamespace, query );
                              
                        ManagementObjectCollection collection = searcher.Get();

                        DateTime bootup;      
                        foreach (ManagementObject item in collection)
                        {
                             string DMTF= item.Properties["LastBootUpTime"].Value.ToString();
                              bootup = ManagementDateTimeConverter.ToDateTime(DMTF).Date;

                              //Compare dates to see if it was today before the 8am Client runs
                              //or if it was yesterday after the Client ran
                              if (bootup == daybefore) //and time after 2pm
                              {
                                    post message if time after 2pm

                              }
                              else if (bootup == today)//and time before 2pm
                              {
                                    post message if time before 2pm
                              }
                  
                        }
                        searcher.Dispose();
                  }
                  catch (Exception e)
                  {
                      System.Diagnostics.EventLog.WriteEntry(this.ToString(),
                        ERROR.FAILED + e.ToString(),
                              System.Diagnostics.EventLogEntryType.Error);
                  }
            }
            
            public  string GetMsgId() {return m_sMsgId;}
            public  int GetMsgNum() {return m_iMsgNum;}
            private static string m_sMsgId = MESSAGETYPES.LAST_PC_RESTART_MONITOR;
            private static int m_iMsgNum = MESSAGENUMBERS.LAST_PC_RESTART_MONITOR;
      }
}
0
Comment
Question by:NewMom2Brandon
[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
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
rcarlan earned 2000 total points
ID: 13697798
                         bootup = ManagementDateTimeConverter.ToDateTime(DMTF);

                         //Compare dates to see if it was today before the 8am Client runs
                         //or if it was yesterday after the Client ran
                         if (bootup.Date==daybefore && bootup.hour>=14) // bootup yesterday after 2pm
                         {
                              post message if time after 2pm

                         }
                         else if (bootup.Date==today && bootup.hour<14) // bootup today before 2pm
                         {
                              post message if time before 2pm
                         }
0
 
LVL 2

Author Comment

by:NewMom2Brandon
ID: 13697989
I did get this error

'System.DateTime' does not contain a definition for 'hour'
0
 
LVL 2

Author Comment

by:NewMom2Brandon
ID: 13698054
got it fixed...sorry!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

801 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