We help IT Professionals succeed at work.

Using a perl script to get ntp time server info from registry on server 2003

tnnetworks
tnnetworks asked
on
937 Views
Last Modified: 2008-11-20
I have a perl script that I want to use to check and see if a windows 2003 server is correctly configured to get time from an ntp server.  It returns an error saying that the ntp server is not configured  Below is a portion of my code that deals with the time server check.  the rest of my script works fine  just the time server check fails.  Any help would be appreciated as I need to run this on approx 40 2003 servers each month.


use Win32::Registry;
    my $tserv;  
$::HKEY_LOCAL_MACHINE->Open("SOFTWARE\\Policies\\Microsoft\\W32Time\\Parameters", $tserv)
        or $tserv_error = 1;

if ($systype =~ backup) {
print "This script is being run on a backup controller, it will not show the correct timeserver IP";
}

if ($tserv_error = 1) {
      print "Error - It looks like the time server has not been configured on this system in gpedit.msc\n\n";  
      $ntpsource = "0.0.0.0";
      $ntpprotocol = "ERROR";
      }
      else
      {
    my ($type, $value);  
$tserv->QueryValueEx("NtpServer", $type, $value);
$tserv->QueryValueEx("Type", $type, $ntpprotocol);
($ntpsource, $junk) = split(',',$value);
print "TIMESERVER: $ntpsource\n";  
print "TIMESERVERTYPE: $ntpprotocol\n";  
      }
Comment
Watch Question

Top Expert 2009

Commented:
Of the code you posted, which line generates the error?

Author

Commented:
it dies not generate any errors it just never gets the time servers IP or type.  The output is sent to a txt file  The output of the txt file is here:  the 61341 is the server name  but I have NTP configured correctly and event view shows successful time syncs.

61341 - TIMESERVER: 0.0.0.0
61341 - TIMESERVERTYPE: ERROR
Top Expert 2009

Commented:
If you open up regedit, and look at the KEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\W32Time\Parameters\Type, what does it show?
CERTIFIED EXPERT

Commented:
Hi !

I have try your script, and i get the same result.

When i have look at the key, there is not folder W32Time. I have check again on a windows server 2003 and again the folder was not here. But in another workstation i have find where is located the folder.

Try to change

$::HKEY_LOCAL_MACHINE->Open("SOFTWARE\\Policies\\Microsoft\\W32Time\\Parameters", $tserv)

by

$::HKEY_LOCAL_MACHINE->Open("SYSTEM\\CurrentControlSet\\Services\\W32Time\\Parameters", $tserv)


Best Regards

Author

Commented:
Under the registry settings when I follow the complete path  KEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\W32Time\Parameters\Type   type show as NTP

There are 3 registry keys under KEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\W32Time\Parameters\

They are
Default  No Value Set
NtpServer REG_SZ 10.1.36.94,0x1
Type   REG_SZ NTP

Author

Commented:
Hi Mad  I tried what you are suggesting however I get the same results.  The script comes back and tells me that it looks like the time server is not configured.
Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.