Execute a programm aways returns (0x00000002)

Maybe it’s helpfull

See for example: http://www.cplusplus.com/reference/cstdlib/system/

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

int main() {
    ShellExecute(NULL, "open", "path\\to\\file.exe", NULL, NULL, SW_SHOWDEFAULT);
}

So i’ve recently started working on a lobby mechanic. And i searched for a way to dynamically start or close servers. And one function i came across was the “FPlatformProcess::CreateProc()” function to obviously start my server instances. It only works when I call it in c++ in the begin play function but when i call it as a BP script it returns this error:
“LogWindows: Warning: CreateProc failed: The system cannot find the file specified. (0x00000002)”

UFUNCTION looks like this:

UFUNCTION(BlueprintCallable, Category = "Function")
	void ExecuteProgramm();

296975-ue4-ufunction.png

For my location i escaped the \ like this \ so i have: “C:\Users\MyName\Programms\ServerFolder\Server.exe”

void AServerCreator::ExecuteProgramm()
{
	FPlatformProcess::CreateProc(TEXT("C:\\Users\\MyName\\Programms\\ServerFolder\\Server.exe"), nullptr, true, false, false, nullptr, 0, nullptr, nullptr);
	return;
	UE_LOG(LogTemp, Warning, TEXT("Code should have been executed hopefully"));
}

I used the log to determine if it was even working as im 103% of a noob in c++

Thanks for the help

magerbeton

Eddit1:
I tested it a second time now to put the FPlatformProcess::CreateProc() in the BeginPlay Function but now it allways returns the error above

Thanks for the Awnser… Ive tried this solution already in a codeblocks test how this function works and it works just fine outside of ue4… but if i include windows.h then it returns a bunch of errors about undefined Process macros as seen in this post:
https://forums.unrealengine.com/development-discussion/c-gameplay-programming/1671896-suddenly-can-t-compile-error-c4668
The ideas in this Forum didnt help in this case.

this was the reason why i tried to use the function FPlatformProcess::CreateProc instead of the ShellExecute function.

I found a solution on how to start stuff during runtime… Its only in BP.

You define the desired Path in a Media file source and launch it as URL like this: