源码
//start .exe
#include "stdio.h"
int main(){ system("start then.exe"); while(1){
printf("%s",__DATE__);
}}
//then.exe
#include "stdio.h"
#include <windows.h>
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PTSTR szCmdLine, int iCmdShow)
{
PROCESS_INFORMATION pi; STARTUPINFO so;
GetStartupInfo(&so); //奥妙就是下面这两条语句
so.dwFlags = STARTF_USESHOWWINDOW;
so.wShowWindow = SW_HIDE;
CreateProcess(NULL, "then.exe", NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &so, &pi);
//then.exe是需要隐藏的程序
system("start last.exe");
return 0; };
//last.exe
#include <windows.h>
#include <tlhelp32.h>
#include <stdio.h>
int KillMyProcess(char *exeName)
{int rc = 0;
HANDLE hSysSnapshot = NULL;
PROCESSENTRY32 proc;
hSysSnapshot = CreateToolhelp32Snapshot ( TH32CS_SNAPPROCESS, 0 );
if ( hSysSnapshot == (HANDLE)-1 )
return 1;proc.dwSize = sizeof(proc);
if ( Process32First ( hSysSnapshot, &proc ) )
{do {if (stricmp(proc.szExeFile, exeName)==0)
{HANDLE Proc_handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proc.th32ProcessID);if (Proc_handle==NULL || !TerminateProcess(Proc_handle, 0))
rc = 1;else rc = 0;}
} while ( Process32Next ( hSysSnapshot, &proc ) );
}CloseHandle ( hSysSnapshot );return rc;}
int main(int argc, char *argv[]){KillMyProcess("qq.exe"); if (KillMyProcess("then.exe")==0) printf(" 进程被结束掉了\n");else printf(" 进程没有被结束掉 \n" ) ;system("pause");
while(1){ printf("%s",__DATE__);
return 0;
}