wei_ziyong
驱动牛犊
驱动牛犊
  • 注册日期2003-12-31
  • 最后登录2010-04-30
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望16点
  • 贡献值0点
  • 好评度16点
  • 原创分0分
  • 专家分0分
阅读:1421回复:11

设置系统的时间?

楼主#
更多 发布于:2005-04-19 13:50
请问在驱动程序中,哪一个函数能够直接设置系统的时间?
请各位高手指点一下!!
aiwadgj
驱动老牛
驱动老牛
  • 注册日期2004-11-13
  • 最后登录2020-12-24
  • 粉丝0
  • 关注0
  • 积分119分
  • 威望84点
  • 贡献值0点
  • 好评度14点
  • 原创分0分
  • 专家分0分
  • 社区居民
沙发#
发布于:2005-04-19 14:40
请问在驱动程序中,哪一个函数能够直接设置系统的时间?
请各位高手指点一下!!


转贴一个。。。

http://www.blogdriver.com/qingbrother/292863.html
酒也在沉溺,何时麻醉我抑郁。过去了的一切会平息。。。。。。。
wei_ziyong
驱动牛犊
驱动牛犊
  • 注册日期2003-12-31
  • 最后登录2010-04-30
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望16点
  • 贡献值0点
  • 好评度16点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2005-04-19 17:32
高手,不对啊,我看了你转发的文章,我在驱动程序中如下声明了该函数,但是,程序编译时有错误;能够看一下这个函数应该
怎样声明,才能够把他使用起来?谢谢啦!!
extern BOOL SetSystemTime(CONST SYSTEMTIME *lpSystemTime);
我是这样调用的,是编译有错。编译器认不到BOOL 类型。
NTSTATUS SDDevice::IOCTL_SET_SYSTEM_TIME_Handler(KIrp I)
{
   NTSTATUS status = STATUS_SUCCESS;
    SYSTEMTIME time;
    time.wYear = 2000;
    time.wMonth = 1;
    time.wDayOfWeek = 1;
    SetSystemTime(&time);
    I.Information() = 0;
    return status;
}

error C2146: syntax error : missing \';\' before identifier \'SetSystemTime\'
C:\\Documents and Settings\\Administrator\\桌面\\418\\SD2407\\sys\\SD2407Device.cpp(1298) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

SD2407.sys - 2 error(s), 0 warning(s)
aiwadgj
驱动老牛
驱动老牛
  • 注册日期2004-11-13
  • 最后登录2020-12-24
  • 粉丝0
  • 关注0
  • 积分119分
  • 威望84点
  • 贡献值0点
  • 好评度14点
  • 原创分0分
  • 专家分0分
  • 社区居民
地板#
发布于:2005-04-19 17:48
我也没有用过这个函数的,,不是说在USER32。DLL里的吗。。。

你找到这个函数对应的声明的头文件,,包进去。。还有定义那个结构的文件哦。。。。

bool改成BOOLEAN   试试。。

还有啊。。你SetSystemTime(&time);不对吧?

改成SetSystemTime(time);吧,,应该。。。

酒也在沉溺,何时麻醉我抑郁。过去了的一切会平息。。。。。。。
aiwadgj
驱动老牛
驱动老牛
  • 注册日期2004-11-13
  • 最后登录2020-12-24
  • 粉丝0
  • 关注0
  • 积分119分
  • 威望84点
  • 贡献值0点
  • 好评度14点
  • 原创分0分
  • 专家分0分
  • 社区居民
地下室#
发布于:2005-04-19 17:59
刚注意到哦,,你这是用DS写驱动那?

那这个函数可以在DS驱动开发中用吗?。。。这可是个用户模式的函数。。。好像不可以这么用的啊。。。。

嗯!,,应该不可以用的,,没有试验过。。呵呵
酒也在沉溺,何时麻醉我抑郁。过去了的一切会平息。。。。。。。
wei_ziyong
驱动牛犊
驱动牛犊
  • 注册日期2003-12-31
  • 最后登录2010-04-30
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望16点
  • 贡献值0点
  • 好评度16点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2005-04-19 18:58
对应该不能够在驱动程序中调用它,我现在还想问一个问题就是驱动
程序中又没有能够直接修改系统时间的函数,因为在应用程都提供了
SetSystemTime()函数可以设置系统时间,我总觉得在驱动程序中
也应该有这个功能的函数才行啊,我看了ddk和ds的帮助文档,只有ddk里说了可以调用函数KeQuerySystemTime()来读取系统的时间,可是就没有找到能够设置系统时间的函数?
aiwadgj
驱动老牛
驱动老牛
  • 注册日期2004-11-13
  • 最后登录2020-12-24
  • 粉丝0
  • 关注0
  • 积分119分
  • 威望84点
  • 贡献值0点
  • 好评度14点
  • 原创分0分
  • 专家分0分
  • 社区居民
6楼#
发布于:2005-04-19 20:41
就得没有直接调用的函数,,那就不好弄了。。。

你非要完成这个功能吗?。。。让那些搞核心编程的老大们。。

来看 看吧。。。。这东西,,俺不是很懂的了。。呵呵。。。
酒也在沉溺,何时麻醉我抑郁。过去了的一切会平息。。。。。。。
arthurtu
驱动巨牛
驱动巨牛
  • 注册日期2001-11-08
  • 最后登录2020-12-19
  • 粉丝0
  • 关注0
  • 积分26分
  • 威望161点
  • 贡献值0点
  • 好评度35点
  • 原创分0分
  • 专家分0分
  • 社区居民
7楼#
发布于:2005-04-19 21:38
ZwSetSystemTime
ZwSetSystemTime sets the system time.
NTSYSAPI
NTSTATUS
NTAPI
ZwSetSystemTime(
IN PLARGE_INTEGER NewTime,
OUT PLARGE_INTEGER OldTime OPTIONAL
);
Parameters
NewTime
Points to a variable that specifies the new time of day in the standard time format (that
is, the number of 100-nanosecond intervals since January 1, 1601).
OldTime
Optionally points to a variable that receives the old time of day in the standard time
format (that is, the number of 100-nanosecond intervals since January 1, 1601).
Return Value
Returns STATUS_SUCCESS or an error status, such as STATUS_PRIVILEGE_NOT_HELD.
Related Win32 Functions
SetSystemTime.
Remarks
SeSystemtimePrivilege is required to set the system time.
maqian
驱动中牛
驱动中牛
  • 注册日期2002-08-07
  • 最后登录2014-09-16
  • 粉丝2
  • 关注1
  • 积分12分
  • 威望120点
  • 贡献值0点
  • 好评度32点
  • 原创分0分
  • 专家分0分
8楼#
发布于:2005-04-20 10:52
可惜,没有早点看到这个贴子,否则分就是我的啦!
五花马,千金裘,呼儿将出换美酒。 我不喝酒,喝可乐。
bmyyyud
驱动老牛
驱动老牛
  • 注册日期2002-02-22
  • 最后登录2010-01-21
  • 粉丝0
  • 关注0
  • 积分1000分
  • 威望130点
  • 贡献值0点
  • 好评度106点
  • 原创分0分
  • 专家分0分
9楼#
发布于:2005-04-20 11:18
ZwSetSystemTime
ZwSetSystemTime sets the system time.
NTSYSAPI
NTSTATUS
NTAPI
ZwSetSystemTime(
IN PLARGE_INTEGER NewTime,
OUT PLARGE_INTEGER OldTime OPTIONAL
);
Parameters
NewTime
Points to a variable that specifies the new time of day in the standard time format (that
is, the number of 100-nanosecond intervals since January 1, 1601).
OldTime
Optionally points to a variable that receives the old time of day in the standard time
format (that is, the number of 100-nanosecond intervals since January 1, 1601).
Return Value
Returns STATUS_SUCCESS or an error status, such as STATUS_PRIVILEGE_NOT_HELD.
Related Win32 Functions
SetSystemTime.
Remarks
SeSystemtimePrivilege is required to set the system time.

老歌从哪里找的,DDK文档中没有,是不是在Native Api那本书里,我找到一大堆,KeSetSystemTime,NtSetSystemTime,ZwSetSystemTime,不知他们被输出了吗?
滚滚长江东逝水 浪花淘尽英雄 是非成败转头空 青山依旧在 几度夕阳红 白发渔樵江渚上 惯看秋月春风 一壶浊酒喜相逢 古今多少事 尽付笑谈中
maqian
驱动中牛
驱动中牛
  • 注册日期2002-08-07
  • 最后登录2014-09-16
  • 粉丝2
  • 关注1
  • 积分12分
  • 威望120点
  • 贡献值0点
  • 好评度32点
  • 原创分0分
  • 专家分0分
10楼#
发布于:2005-04-20 14:47
输出了,但DDK的头文件中没有相应的声明,你要自己写。(拷贝、粘贴)。 :)
五花马,千金裘,呼儿将出换美酒。 我不喝酒,喝可乐。
armstrongest
驱动牛犊
驱动牛犊
  • 注册日期2005-05-03
  • 最后登录2005-05-03
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
11楼#
发布于:2005-05-03 13:33
//OK THROUGH VC6.0
// setsystemtime.cpp : Defines the entry point for the console application.
//

#include \"stdafx.h\"
#include \"setsystemtime.h\"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T(\"Fatal Error: MFC initialization failed\") << endl;
nRetCode = 1;
}
else
{
// TODO: code your application\'s behavior here.
CFile Rfile,Rfile2;
CString strHello;
if (Rfile.Open(_T(\"d:\\\\1.txt\"),CFile::modeRead))
{
char st[20];
int stlen,m_Year,m_Month,m_Day,m_Hour,m_Minute,m_Second;
memset(st,\'\\0\',20);
stlen = Rfile.Read(&st,20);
Rfile.Close();
Rfile.Remove(_T(\"d:\\\\1.txt\"));

cout << (LPCTSTR)st << endl;
cout << stlen << endl;

CString temp;
temp = LPCTSTR(st);
m_Year = atoi(temp.Left(4));
temp = temp.Right(temp.GetLength() -5);
m_Month = atoi(temp.Left(2));
temp = temp.Right(temp.GetLength() -3);
m_Day = atoi(temp.Left(2));
temp = temp.Right(temp.GetLength() -3);
m_Hour = atoi(temp.Left(2));
temp = temp.Right(temp.GetLength() -3);
m_Minute = atoi(temp.Left(2));
m_Second = 0;

SYSTEMTIME systime;
memset(&systime,0,sizeof(SYSTEMTIME));
systime.wYear = m_Year;
systime.wMonth = m_Month;
systime.wDay = m_Day;
systime.wHour = m_Hour;
systime.wMinute = m_Minute;
systime.wSecond = m_Second;


CTime ct(systime, -1);
CTimeSpan cts(1,0,0,0);
ct += cts;

systime.wYear = ct.GetYear();
systime.wMonth = ct.GetMonth();
systime.wDay = ct.GetDay();
systime.wHour = ct.GetHour();
systime.wMinute = ct.GetMinute();
systime.wSecond = ct.GetSecond();

if (SetLocalTime(&systime))
{
cout << (_T(\"Set System Time ok\")) << endl;


char s_Year[4],s_Month[2],s_Day[2],s_Hour[2],s_Minute[2],s_Second[2];
itoa(systime.wYear,s_Year,10);
itoa(systime.wMonth,s_Month,10);
itoa(systime.wDay,s_Day,10);
itoa(systime.wHour,s_Hour,10);
itoa(systime.wMinute,s_Minute,10);
itoa(systime.wSecond,s_Second,10);

strcpy(st,s_Year);
strcat(st,\"-\");
if (systime.wMonth<10) strcat(st,\"0\");
strcat(st,s_Month);
strcat(st,\"-\");
if (systime.wDay<10) strcat(st,\"0\");
strcat(st,s_Day);
strcat(st,\" \");
if (systime.wHour<10) strcat(st,\"0\");
strcat(st,s_Hour);
strcat(st,\":\");
if (systime.wMinute<10) strcat(st,\"0\");
strcat(st,s_Minute);
strcat(st,\":\");
if (systime.wSecond<10) strcat(st,\"0\");
strcat(st,s_Second);

temp = LPCTSTR(st);
if (Rfile2.Open(_T(\"d:\\\\1.txt\"),CFile::modeWrite | CFile::modeCreate))
{
Rfile2.Write(temp,temp.GetLength());
Rfile2.Close();
}
else
{
cout << (_T(\"Create d:\\\\1.txt failed\")) << endl;
getchar();
}
}
else
{
cout << (_T(\"Set System time failed\")) << endl;
getchar();

}

}
else
{
strHello.LoadString(IDS_BYE);
cout << (LPCTSTR)strHello << endl;
getchar();
}
}

return nRetCode;
}

游客

返回顶部