超级版主
注册日期: 04-03
帖子: 18592
精华: 36
现金: 249466 标准币
资产: 1080358888 标准币
|
回复: 使用c#设置系统时间(不同于以往的文章,是经过测试的)
种方法是调用Win32 API SetSystemTime.
using System.Runtime .InteropServices ;
[ StructLayout( LayoutKind.Sequential )]
public class SystemTime
{
public ushort year;
public ushort month;
public ushort dayOfWeek;
public ushort day;
public ushort hour;
public ushort minute;
public ushort second;
public ushort milliseconds;
}
class MainClass
{
[ DllImport( "Kernel32.dll" )]
public static extern void GetSystemTime( [In,Out] SystemTime st );
[ DllImport( "Kernel32.dll" )]
public static extern bool SetSystemTime( [In,Out] SystemTime st );
public static void Main(string[] args)
{
SystemTime st=new SystemTime ();
GetSystemTime(st);
st.year +=1;
bool result=SetSystemTime(st);
}
}
微软亚洲技术中心 VC技术支持
__________________
借用达朗贝尔的名言:前进吧,你会得到信心!
[url="http://www.dimcax.com"]几何尺寸与公差标准[/url]
|