Need help here, I'm trying to create a process in c++ with the windows api, whats happening is the process is being created which is cmd.exe however I want cmd.exe to open cd'd at a certain directory i.e. root c:\, however the process is opened at the dir of the executable. I tried passing in "cd \" as the second argument of the CreateProcess function to no avail
Here's a snippet of the code:
TCHAR program[] = TEXT("C:/Windows/System32/cmd.exe");
TCHAR command[] = TEXT("cd /");
STARTUPINFO info;
PROCESS_INFORMATION processInfo;
ZeroMemory(&info,sizeof(STARTUPINFO));
ZeroMemory(&processInfo,sizeof(PROCESS_INFORMATION));
BOOL processResult =
CreateProcess(program,
command, NULL, NULL,
TRUE, CREATE_NEW_CONSOLE,
NULL, NULL,
&info,
&processInfo);
if(!processResult){
std::cerr << "CreateProcess() failed to start program \""
<< program << "\"\n";
exit(1);
}
std::cout << "Started program \""
<< program << "\" successfully\n";
Help would be extremely appreciated! Thanks