Use WMI to query and set time and date on remote systems. You may need to
adjust privileges for your account to set time/date on the remote machine.

use Win32::OLE qw(in);

my $datetime = Win32::OLE->new("WbemScripting.SWbemDateTime") or die;
my $machine = shift @ARGV or ".";
$machine =~ s/^[\\\/]+//;
my $wmiservices =
Win32::OLE->GetObject("winmgmts:{impersonationLevel=impersonate,(security)}//$machine")
or die;
foreach my $os ( in( $wmiservices->InstancesOf("Win32_OperatingSystem")))
{
  print "Last Boot Time:".$os->{LastBootUpTime}."\n";
  print "Current time:".$os->{LocalDateTime}."\n";
  $datetime->{Value} = $os->{LocalDateTime};
  printf( "Current Time: %02d-%02d-%04d at %02d:%02d:%02d\n",
$datetime->{Month}, $datetime->{Day}, $datetime->{Year}, $datetime->{Hours},
$datetime->{Minutes}, $datetime->{Seconds} );
  print "Setting time + 2 hours:";
  $datetime->{Hours} += 2;
  printf( "Current Time: %02d-%02d-%04d at %02d:%02d:%02d\n",
$datetime->{Month}, $datetime->{Day}, $datetime->{Year}, $datetime->{Hours},
$datetime->{Minutes}, $datetime->{Seconds} );
  print "\tHard value: $datetime->{Value}\n";
  $Result = $os->SetDateTime($datetime->{Value});
  print "Result: $Result\n";
}

On Wed, Sep 28, 2011 at 4:04 AM, <william.hoo...@l-3com.com> wrote:

> I've used Win32-OLE to start/execute processes on remote computers.  In
> this scenario you could use Win32-OLE to call time
>
>
>
> -----Original Message-----
> From: perl-win32-users-boun...@listserv.activestate.com
> [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of
> Barry Brevik
> Sent: Monday, September 26, 2011 8:24 PM
> To: Tobias Hoellrich; Howard Tanner;
> perl-win32-users@listserv.ActiveState.com
> Subject: RE: Setting file server time
>
> Yes NTP. Well, if the guy had it setup right it would work, but no. So I
> had to create an internet time server bot (with a little help) which
> sets the local machine time. I was hoping to employ a Win32-only
> solution to then set the domain controller rather than spawn one of the
> pstools (I am familiar with them).
>
>
> > -----Original Message-----
> > From: perl-win32-users-boun...@listserv.activestate.com
> > [mailto:perl-win32-users-boun...@listserv.activestate.com] On
> > Behalf Of Tobias Hoellrich
> > Sent: Monday, September 26, 2011 4:44 PM
> > To: Howard Tanner; perl-win32-users@listserv.ActiveState.com
> > Subject: RE: Setting file server time
> >
> > Since the advent of NTP on the Windows platforms I don't
> > remember the last time there was a need to set the time manually :-)
> >
> > Thanks- T
> >
> > -----Original Message-----
> > From: Howard Tanner [mailto:tan...@optonline.net]
> > Sent: Monday, September 26, 2011 5:26 PM
> > To: Tobias Hoellrich; 'Barry Brevik';
> > perl-win32-users@listserv.ActiveState.com
> > Subject: RE: Setting file server time
> >
> > NET TIME was my first thought too, but it only allows you to
> > set your time to that of another machine.
> >
> > _______________________________________________
> > Perl-Win32-Users mailing list
> > Perl-Win32-Users@listserv.ActiveState.com
> > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> >
> >
> _______________________________________________
> Perl-Win32-Users mailing list
> Perl-Win32-Users@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> _______________________________________________
> Perl-Win32-Users mailing list
> Perl-Win32-Users@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to