//用法:CDate.exe 20170530 (其中CDate.exe为生产的编译名)
//使用SetSystemTime函数会有一个时区差,也可以使用SetLocalTime函数修改,用法一样
#include <windows.h>
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
int main(int argc, char* argv[]) {
string str = argv[1];
string year(str.substr(0, 4)), mouth(str.substr(4, 2)), day(str.substr(6, 2));
SYSTEMTIME sys = {0};
GetSystemTime(&sys);
sys.wYear = atoi(&year[0]);
sys.wMonth = atoi(&mouth[0]);
sys.wDay = atoi(&day[0]);
if (0 == SetSystemTime(&sys)){
system("echo error > C:\\Recovery\\OEM\\Backup\\CDatelog");
return -1;
}
system("echo OK > C:\\Recovery\\OEM\\Backup\\CDatelog");
return 0;
}