修改系统时间 (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();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值