i am having trouble incorporating this createprocess function with opening a execultable.. it is in c++ and i keep getting 2 error messages which are
C:\Program Files\Microsoft Visual Studio\MyProjects\process\process.cpp(24) : error C2143: syntax error : missing ')' before ';'
C:\Program Files\Microsoft Visual Studio\MyProjects\process\process.cpp(27) : error C2065: 'IpApplicationName' : undeclared identifier
and here is my code

bool CreateProcess(
					char IpApplicationName[1000];
					STARTUPINFO StartInfo;
					PROCESS_INFORMATION ProcessInfo;
					strcpy(IpApplicationName, "c:\\windows\\system32\\calc.exe");
					ZeroMemory(&StartInfo, sizeof(StartInfo));
					StartInfo.cb = sizeof(StartInfo);
						if (!CreateProcess(IpApplicationName, NULL, NULL, NULL, FALSE,
						HIGH_PRIORITY_CLASS | CREATE_NEW_CONSOLE, NULL, NULL, 
						&StartInfo, &ProcessInfo))
					
						 printf("===Closing  the copy File Process, continue>===\n\n");
						 CloseHandle(&ProcessInfo.hThread);
						 CloseHandle(&ProcessInfo.hProcess);
		}

Dani AI

Generated

The errors shown by come from a syntax/structural mistake, not from CreateProcess itself. The code starts with a line that looks like a function definition (bool CreateProcess() but then contains ordinary statements terminated with semicolons where a parameter list and a closing ) are expected. That produces the "missing ')' before ';'" error and causes later identifiers (like IpApplicationName) to be reported as undeclared because the compiler never finished parsing the earlier declaration. Do not try to redefine or shadow the Win32 API function name; put the call inside a normal function (for example main) or give any wrapper a different name.

Also note the important API semantics that explain some of the runtime pitfalls: CreateProcess maps to CreateProcessA or CreateProcessW depending on the build, and the command-line parameter passed as the second argument must be a writable buffer because the function may modify it. As pointed out, CloseHandle takes a HANDLE, not a pointer — pass the handle itself (for example pi.hThread), not &pi.hThread.

A minimal, safe pattern (narrow/ANSI form) is shown below; it demonstrates proper scoping, error checking, waiting and handle cleanup:

#include <windows.h>
#include <cstdio>

int main()
{
    char cmd[] = "C:\\Windows\\System32\\calc.exe";
    STARTUPINFOA si;
    PROCESS_INFORMATION pi;
    ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);

    if (CreateProcessA(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
    {
        WaitForSingleObject(pi.hProcess, INFINITE);
        CloseHandle(pi.hProcess);
        CloseHandle(pi.hThread);
    }
    else
    {
        printf("CreateProcess failed: %lu\n", GetLastError());
    }
    return 0;
}

Troubleshooting notes: include <windows.h>, use CreateProcessA/CreateProcessW deliberately when mixing narrow/wide strings, prefer strcpy_s or std::string instead of strcpy, and use GetLastError (or FormatMessage) to get human-readable failure reasons.

Nothing is wrong with your code. It compiles fine in my Visual Studio 2002 compiler.
Anyway the following change is needed.

CloseHandle(ProcessInfo.hThread);
	CloseHandle(ProcessInfo.hProcess);

Maybe the error is not in the code you posted.

This is the code I tested it in

#include <windows.h>
#include <iostream>

int main()
{
char IpApplicationName[1000];
					STARTUPINFO StartInfo;
					PROCESS_INFORMATION ProcessInfo;
					strcpy(IpApplicationName, "c:\\windows\\system32\\calc.exe");
					ZeroMemory(&StartInfo, sizeof(StartInfo));
					StartInfo.cb = sizeof(StartInfo);
						if (!CreateProcess(IpApplicationName, NULL, NULL, NULL, FALSE,
						HIGH_PRIORITY_CLASS | CREATE_NEW_CONSOLE, NULL, NULL, 
						&StartInfo, &ProcessInfo))
					
						std::cout<<("===Closing  the copy File Process, continue>===\n\n");	//WaitForSingleObject( ProcessInfo.hProcess, INFINITE );

    // Close process and thread handles. 

	CloseHandle(ProcessInfo.hThread);
	CloseHandle(ProcessInfo.hProcess);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.