隐藏本身,分为如下几步,缺一不可:
第一步 #pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
后者完整一点的:
#ifdef _ConsoleDisappear
#pragma comment( linker, "/subsystem:/"windows/" /entry:/"wmainCRTStartup/"")
#else
#pragma comment( linker, "/subsystem:/"windows/" /entry:/"mainCRTStartup/"")
#endif
第二步:Project---->Properties--->Linker--->Advanced--->Entery Point修改为"mainCRTStartup"。
第三步:Project---->Properties--->Linker--->System-->Subsystem改成Windows(/SUBSYSTEM:WINDOWS)
隐藏启动程序
void ExecDOSCMD(char * szCommand)
{
STARTUPINFO si;
memset(&si, 0, sizeof(STARTUPINFO));
// 进程信息
PROCESS_INFORMATION pi;
si.cb = sizeof(STARTUPINFO);
// 取得当前进程的StartupInfo,并根据当前进程进行修改
GetStartupInfo(&si);
si.wShowWindow = SW_SHOW;
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
char temp[4096] = "";//此处不加cmd /k
strcat(temp, szCommand);
CreateProcess(NULL, (LPSTR)(LPCTSTR)(temp), NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
}
ExecDOSCMD("demo.exe -d \\\\.\\usbpcap6 -o log");