// setTime.cpp : Defines the entry point for the console application.
//
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
void usage()
{
system("cls.exe");
printf("-------------------------------------------------------/n"
"/tsetTime Ver 1.0 zhouzhen[E.S.T], 2005/3/5/n"
"/thttp://www.eviloctal.com, [email]zhouzhen@yeah.net[/email]/n"
"/t 文件时间修改器 1.0"
"/n/n"
"/tUsage: /tsetTime OldFile NewFile/n"
"/tExample: /tsetTime hello.asp eviloctal.asp/n"
"--------------------------------------------------------/n"
);
exit(0);
}
int main(int argc, char* argv[])
{
HANDLE hFileOld, hFileNew;
FILETIME OCreateTime, OLastAccessTime, OLastWriteTime;
const FILETIME *pCreationTime, *pLastAccessTime, *pLastWriteTime;
if (argc!=3)
usage();
else{
hFileOld = CreateFile(argv[1], GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFileOld == INVALID_HANDLE_VALUE)
{
printf("Cannot open %s. Error:%x/n", argv[1], GetLastError());
exit(1);
}
hFileNew = CreateFile(argv[2], GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFileNew == INVALID_HANDLE_VALUE)
{
printf("Cannot open %s. Error:%x/n", argv[2], GetLastError());
exit(2);
}
GetFileTime(hFileOld , &OCreateTime, &OLastAccessTime, &OLastWriteTime);
pCreationTime = &OCreateTime;
pLastAccessTime = &OLastAccessTime;
pLastWriteTime = &OLastWriteTime;
SetFileTime(hFileNew, pCreationTime, pLastAccessTime,pLastWriteTime);
CloseHandle(hFileNew);
CloseHandle(hFileOld);
printf("All is done! Enjoy yourself/n");
}
return 0;
}