- 论坛徽章:
- 1
|
哪个模块可以更改windows的时期和时间?
折腾了一晚上,终于搞定楼主的问题了:
- #!/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();
复制代码 |
|