+ Reply to Thread
Results 1 to 2 of 2

Thread: What are the different ways to create a new process?

  1. #1

    What are the different ways to create a new process?

    What are the different ways to create a new process?

  2. #2
    You can use one of following functions to create a process:

    a. ShellExecuteEx
    b. ShellExecute
    c. CreateProcess
    d. WinExec
    e. system

    Example:

    Code:
    void UseShellExecuteEx()
    {
    	SHELLEXECUTEINFO ShExecInfo ;
    
    	ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO) ;
    	ShExecInfo.fMask = NULL ;
    	ShExecInfo.hwnd = NULL ;
    	ShExecInfo.lpVerb = NULL ;
    	ShExecInfo.lpFile = "calc.exe" ;
    	ShExecInfo.lpParameters = NULL ;
    	ShExecInfo.lpDirectory = NULL ;
    	ShExecInfo.nShow = SW_NORMAL ;
    	ShExecInfo.hInstApp = NULL ;
    	
    	ShellExecuteEx(&ShExecInfo);
    }
    
    void UseShellExecute()
    {
    	ShellExecute(NULL, "open", "calc.exe", NULL, NULL, SW_SHOWNORMAL) ;
    }
    
    void UseCreateProcess()
    {
    	PROCESS_INFORMATION objProcessInfo ;
    	memset(&objProcessInfo, 0, sizeof(objProcessInfo)) ;
    
    	STARTUPINFO objStartInfo ;
    	memset(&objStartInfo, 0, sizeof(objStartInfo)) ;
    	objStartInfo.cb = sizeof(objStartInfo) ;
    
    	CreateProcess(NULL, "calc.exe", NULL, NULL, FALSE, 0, NULL, NULL, &objStartInfo, &objProcessInfo) ;
    	CloseHandle(objProcessInfo.hProcess) ;
        CloseHandle(objProcessInfo.hThread) ;
    }
    
    void UseWinExe()
    {
    	WinExec("calc.exe", SW_NORMAL) ;
    }
    
    void UseSystem()
    {
    	system("calc.exe") ;
    }

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts