This is not a problem, more a good to know topic. I can life without an solution but it was nice to have an Solution.
When i run my .exe with normal privileges i got the correct path where the .exe is saved. When i run the .exe with highest privileges the returned path is "C:\Windows\System32"
. The correct location is i.e. "C:\Msys64\home\testproject\"
.
My code to get the path uses the Windows command "cd":
bool get_path(Arg* arg)
{
//This function will only return the correct path when not run with highest privilegs over Taskscheduler
FILE* fp = _popen("cd", "r");
arg->workingdir_cnt = 0;
while (!(feof(fp)))
{
arg->workingdir[arg->workingdir_cnt++] = fgetc(fp);
if (arg->workingdir_cnt > sizeof(arg->workingdir)) { fclose(fp); return 0; }
}
_pclose(fp);
//Add backslash for future use
arg->workingdir[arg->workingdir_cnt-2] = '\\';
arg->workingdir[arg->workingdir_cnt-1] = '\0';
return 1;
}