Click here to Skip to main content
Licence CPOL
First Posted 15 Feb 2007
Views 31,030
Downloads 129
Bookmarked 13 times

Daylight Saving Time 2007: Update Windows Servers and Workstations

By | 8 Mar 2007 | Article
Search through your Active Directory structure to find Windows OSs then apply new Daylight Saving Time rules without paying for the hotfix update or needing to reboot due to Group Policy.

Introduction

New Daylight Saving Time rules go into effect on March 11th, 2007 at 2 AM. Microsoft has provided some sample instructions for updating systems, but there are some serious drawbacks:

  • There is no support for Windows 2000 servers or workstations. Actually there is but you have to pay for "Extended Support" to get it.
  • The patch for Windows Server 2003 is "optional" so you have to select Custom Windows Updates - not Critical Updates which are the default. THIS IS NO LONGER THE CASE; MICROSOFT RECENTLY CHANGED THE PATCH TO CRITICAL.
  • The solution Microsoft proposes for updating multiple computers involves a Computer node Group Policy Object, which is fine but it does require a reboot.

Here is the Microsoft KB on the subject.

Solution

What I did was put together a console application that queries the AD structure by operating system, then uses SysInternal's PsExec tool to execute a registry update on multiple remote machines.

ENVIRONMENT: Visual Studio 2005, .NET 2.0, C# (you will need to add the reference for System.DirectoryServices)

Here is the code:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.DirectoryServices;
using System.Diagnostics;

namespace MyNamespace
{
  class Program
  {
  static void Main(string[] args)
  {
    SearchResultCollection results = null;

    StreamWriter sw = new StreamWriter("\\\\sharename\\DST$\\results.log", true);
    StreamWriter swerr = new StreamWriter("\\\\sharename\\DST$\\errors.log", true);

    try
    {
    // Bind to a container.
    string path = "<a href="ldap://DC=ABC,DC=DEF,DC=org/">ldap://DC=ABC,DC=DEF,DC=org/</a>";

    DirectoryEntry entry = new DirectoryEntry(path);

    // Create a DirectorySearcher object.
    DirectorySearcher mySearcher = new DirectorySearcher(entry);
    mySearcher.PropertiesToLoad.Add("name");
    mySearcher.PropertiesToLoad.Add("operatingsystem");
    // Set a filter for W2K servers. Can also be used for 2003
    // mySearcher.Filter = 
    // "(&(objectCategory=computer)(operatingSystem=Windows Server 2003))";
    // Testing a single machine would look like this
    // mySearcher.Filter = "(&(objectCategory=computer)
    // (operatingSystem=Windows 2000 Server)(name=SERVERNAME))";

    mySearcher.Filter = "(&(objectCategory=computer)
                    (operatingSystem=Windows 2000 Server))";

    results = mySearcher.FindAll();

    foreach (SearchResult searchResult in results)
      {
        ResultPropertyValueCollection valcol = searchResult.Properties["name"];
        {
        // Write the value contained in index position 0 in the name attribute.

        string pc = valcol[0].ToString();

        // User needs to be a Domain Admin or a local admin on the remote computer
        string psargs = "\\\\" + pc + " -u DOMAIN\\username -p password 
                    <a>\\\\sharename\\DST$\\DSTUpdate.bat";

</a>        Process proc = new Process();
        proc.StartInfo.FileName = "C:\\sharename\\DST\\psexec.exe";
        proc.StartInfo.Arguments = psargs;
        proc.StartInfo.UseShellExecute = false;
        proc.StartInfo.RedirectStandardOutput = true;
        proc.Start();
        proc.WaitForExit();

        string output = proc.StandardOutput.ReadToEnd();

        // This is done this way because SysInternal's PsExec 
        // does not handle StandardOutput and StandardError
        // when running on a remote machine 
        sw.WriteLine("Computer: " + pc + 
                 " Result(blank = no update): " + output + "\r\n");
        sw.Flush();

        proc.Close();

        }
      }
    }

    catch (Exception ex)
    {
      swerr.WriteLine("Error: " + ex.Message);
    }

    finally
    {
      // To prevent memory leaks, always call 
      // SearchResultCollection.Dispose() manually.
      if (null != results)
      {
      results.Dispose();
      results = null;
      }

    sw.Close();
    swerr.Close();
    }

  }//end main
  }//end class
}// end namespace

The file DTSUpdate.bat has just three lines:

@echo off
regedit /s \\sharename\DST$\DSTRegistry.reg
cscript \\sharename\DST$\DSTInfo.vbs

Both of these files (DSTRegistry.reg and DSTInfo.vbs) come directly from Microsoft's Web site.

Conclusion

It seems like the DST issue is sneaking up on a lot of companies. It's probably not going to be that big of a deal, but it is best to be prepared. I thought there would already be something similar posted, but I found nothing... so I am putting it out for general use. If someone finds a way to pipe the PsExec output to a file, I would really like to know how that is done. Thanks.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

smoore4

Database Developer

United States United States

Member

I am an MBA, MCSA, MCDBA, and recently MCITP: Database Administrator 2008. Although employed as a DBA, I do a good deal of sys admin work and development using .NET. Technically, I like to focus on business intelligence, database design, messaging architectures and web development/design.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionI can't get PSEXEC to work... PinmemberBrucekConvergent8:42 7 Mar '07  
AnswerRe: I can't get PSEXEC to work... Pinmembersmoore49:24 7 Mar '07  
GeneralIssue Solved... PinmemberBrucekConvergent10:16 7 Mar '07  
GeneralUNC Path to bat file PinmemberBernie Walker5:06 26 Feb '07  
GeneralRe: UNC Path to bat file Pinmembersmoore45:21 26 Feb '07  
Generaluse code project style for your code Pinmemberpita20009:13 23 Feb '07  
GeneralPSExec output redirection PinmemberStryder114:01 20 Feb '07  
GeneralRe: PSExec output redirection Pinmembersmoore416:22 20 Feb '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 8 Mar 2007
Article Copyright 2007 by smoore4
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid