我的记性不是太好,总忘记什么来上班的。所以琢磨着怎么自己搞一个这样的小工具。
这不,刚好这几天工作不是太忙,做了一个小工具。
当你登陆系统时,它会判断你今天是否是第一次登陆,如果是的话,则向Microsoft OutLook
发送一个8小时后的“约会”。这样到你下班的时候,OutLook 就会提醒你该下班了。
这个工具分成三部分。
第一:Windows登陆事件监视器,它是一个dll文件。是用C 开发的。部分源代码如下
__declspec(dllexport) void __stdcall testlogon(DWORD unknow)
{
//到临时目录下查找文件login.log,
//1.如果找到,查看该文件的修改时间
//2.没有则创建一个空文件,并且执行一个创建OutLook Appointment 的程序
char tempPath[80];
char fileName[] = "login.log";
int i = 0;
DWORD len;
FILE * FileHandle;
struct tm *newtime;
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
ZeroMemory(tempPath,sizeof(tempPath));
len = GetTempPath(sizeof(tempPath),tempPath);
for(i = 0 ;i< sizeof(fileName);i++)
{
tempPath[i+len] = fileName[i];
}
if(FileExists(tempPath) == 1)
{
//
printf("login1");
newtime = GetFileMofiedTime(tempPath);
if( IsToday(*newtime) == 0)
{
//free(newtime);
remove(tempPath);
}
else
{
//free(newtime);
return 1;
}
}
printf("login2");
// Sleep(1000);
// if(FileExists(tempPath) == 1)
// {
// FileHandle = fopen(tempPath,"r+");
// }
// else
{
FileHandle = fopen(tempPath,"w+");
}
if(FileHandle != NULL)
{
fwrite(".",1,1,FileHandle);
fclose(FileHandle);
}
//MessageBox(NULL,"login3",tempPath,MB_OK);
if(!CreateProcess(NULL,"NewAppoint.exe",NULL,NULL,FALSE,0,NULL,NULL,&si,&pi))
{
printf("login4");//,tempPath,MB_OK);
return 1;
}
else
{
printf("login5");//"login5",tempPath,MB_OK);
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
return 1;
}
{
//到临时目录下查找文件login.log,
//1.如果找到,查看该文件的修改时间
//2.没有则创建一个空文件,并且执行一个创建OutLook Appointment 的程序
char tempPath[80];
char fileName[] = "login.log";
int i = 0;
DWORD len;
FILE * FileHandle;
struct tm *newtime;
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
ZeroMemory(tempPath,sizeof(tempPath));
len = GetTempPath(sizeof(tempPath),tempPath);
for(i = 0 ;i< sizeof(fileName);i++)
{
tempPath[i+len] = fileName[i];
}
if(FileExists(tempPath) == 1)
{
//
printf("login1");
newtime = GetFileMofiedTime(tempPath);
if( IsToday(*newtime) == 0)
{
//free(newtime);
remove(tempPath);
}
else
{
//free(newtime);
return 1;
}
}
printf("login2");
// Sleep(1000);
// if(FileExists(tempPath) == 1)
// {
// FileHandle = fopen(tempPath,"r+");
// }
// else
{
FileHandle = fopen(tempPath,"w+");
}
if(FileHandle != NULL)
{
fwrite(".",1,1,FileHandle);
fclose(FileHandle);
}
//MessageBox(NULL,"login3",tempPath,MB_OK);
if(!CreateProcess(NULL,"NewAppoint.exe",NULL,NULL,FALSE,0,NULL,NULL,&si,&pi))
{
printf("login4");//,tempPath,MB_OK);
return 1;
}
else
{
printf("login5");//"login5",tempPath,MB_OK);
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
return 1;
}
第二:注册这个监视器dll,是用下面的注册表文件注册的
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Notify\GoHome]
"DLLName"="LogIn.dll"
"Logon"="testlogon"
"Impersonate"=dword:00000001
"Asynchronous"=dword:00000001
"Unlock"="testlogon"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Notify\GoHome]
"DLLName"="LogIn.dll"
"Logon"="testlogon"
"Impersonate"=dword:00000001
"Asynchronous"=dword:00000001
"Unlock"="testlogon"
第三:向OutLook发送约会的程序,源文件是用C#开发的。如下:
Microsoft.Office.Interop.Outlook.ApplicationClass outLookApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();
AppointmentItemClass appointItem = (AppointmentItemClass)outLookApp.CreateItem(OlItemType.olAppointmentItem);
//appointItem
appointItem.Location = "RPC";
appointItem.Subject = "It's time to go home";
appointItem.Importance = OlImportance.olImportanceNormal;
appointItem.Body = "Shark Xu.";
appointItem.BusyStatus = OlBusyStatus.olOutOfOffice;
appointItem.Duration = 1;
appointItem.Start = System.DateTime.Now.AddHours(8.0);
appointItem.ReminderMinutesBeforeStart = 1;
appointItem.Sensitivity = OlSensitivity.olNormal;
appointItem.Save();
AppointmentItemClass appointItem = (AppointmentItemClass)outLookApp.CreateItem(OlItemType.olAppointmentItem);
//appointItem
appointItem.Location = "RPC";
appointItem.Subject = "It's time to go home";
appointItem.Importance = OlImportance.olImportanceNormal;
appointItem.Body = "Shark Xu.";
appointItem.BusyStatus = OlBusyStatus.olOutOfOffice;
appointItem.Duration = 1;
appointItem.Start = System.DateTime.Now.AddHours(8.0);
appointItem.ReminderMinutesBeforeStart = 1;
appointItem.Sensitivity = OlSensitivity.olNormal;
appointItem.Save();
我还做了一个安装文件,它是一个批处理文件
copy Login.dll %SystemRoot%\System32\
copy newAppoint.exe %SystemRoot%\System32\
regedit /s GoHome.reg
copy newAppoint.exe %SystemRoot%\System32\
regedit /s GoHome.reg
完全下载(包括所有的源文件和编译后的程序)