zzbb 发表于 2017-5-18 08:26:19

修改系统时间 (perl)

转载
调用windows api
#!/usr/bin/perl -w
# 2005.01.05 习作于武汉 writed by flw
use strict;
use Win32::API;
use Tk;
my $ret;
Win32::API::Struct->typedef( 'TIMESTRUCT' => qw(
    WORD wYear;
    WORD wMonth;
    WORD wDayOfWeek;
    WORD wDay;
    WORD wHour;
    WORD wMinute;
    WORD wSecond;
    WORD wMilliseconds;
    ) )die "typedef struct TIMESTRUCT failed: [$!]\n";
$ret = Win32::API->Import( 'Kernel32.dll', 'VOID GetLocalTime( LPTIMESTRUCT time )' );
die "Import Win32API GetLocalTime failed: [$!]\n" unless $ret;
$ret = Win32::API->Import( 'Kernel32.dll', 'BOOL SetLocalTime( LPTIMESTRUCT time )' );
die "Import Win32API SetLocalTime failed: [$!]\n" unless $ret;
my $win = new Tk::MainWindow( '-title' => 'flw' );
my $labelText = 'Press OK to set local time';
$win->Label( '-textvariable' => \$labelText )->pack();
$win->Button( '-text' => 'OK', '-command' => \&OnOK )->pack();
sub OnOK{
    my $timeVar = Win32::API::Struct->new( 'TIMESTRUCT' );
    $timeVar->align(0);
    GetLocalTime( $timeVar );
    $timeVar->{ 'wYear' } = 2005;
    $timeVar->{ 'wMonth' } = 1;
    $timeVar->{ 'wDay' } = 23;
    my $ret = SetLocalTime( $timeVar );
    $labelText = "ret: [$ret]".($ret ? 'success' : "failed: [$!]");
}
MainLoop();
页: [1]
查看完整版本: 修改系统时间 (perl)