无聊的一个自我复制的小程序

也为了了解createprocess各参数之用,可以修改其中的安全参数和继承参数等

#include <Windows.h>
#include <tchar.h>
#include <strsafe.h>


#ifndef _UNICODE
#define _UNICODE
#endif


int _tmain(int argc, TCHAR* argv[], TCHAR* env[])
{
	LPCWSTR lpAppName = NULL;
	LPWSTR lpCmdLine = (LPWSTR)malloc(18);
	StringCchCopy(lpCmdLine, wcslen(L"notepad")+1, L"notepad");
	LPWSTR lpCmdLine2 = (LPWSTR)malloc(30);
	StringCchCopy(lpCmdLine2, wcslen(L"CreateProcess.exe") + 1, L"CreateProcess.exe");

	LPSECURITY_ATTRIBUTES lpProcessAttri = NULL;
	LPSECURITY_ATTRIBUTES lpThreadAttri = NULL;
	BOOL bInheritH = FALSE;

	DWORD dwCreadtionFlags = 0;
	// dwCreadtionFlags = NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE | CREATE_NEW_PROCESS_GROUP;
	LPVOID lpEnvironment = NULL;
	LPCWSTR lpCurrentDir = NULL;

	STARTUPINFO si;
	PROCESS_INFORMATION pi;
	ZeroMemory(&si, sizeof(si));
	ZeroMemory(&pi, sizeof(pi));
	si.cb = sizeof(si);


	CreateProcessW(
		lpAppName,
		lpCmdLine,
		lpProcessAttri, 
		lpThreadAttri, 
		bInheritH,
		dwCreadtionFlags,
		lpEnvironment, 
		lpCurrentDir,
		&si,
		&pi);

	CreateProcessW(
		lpAppName,
		lpCmdLine2,
		lpProcessAttri,
		lpThreadAttri,
		bInheritH,
		dwCreadtionFlags,
		lpEnvironment,
		lpCurrentDir,
		&si,
		&pi);
	WaitForSingleObject(pi.hProcess, INFINITE);
	CloseHandle(pi.hProcess);
	CloseHandle(pi.hThread);
	return 0;
}