I got it. I believe the error to originate from the same issue as texlive, from this line:
DWORD len = GetLongPathNameW(this->ToWideCharString().c_str(), longPathName, _MAX_PATH);
Turns out I have to give relative paths to my pdflatex command, for some reason it does not support absolute paths when ran from this network service account. I moved my test/in and test/out in the wwwroot and it works after this small change: D:\miktex\miktex\bin\x64\pdflatex -output-directory=tex\out tex\in\token.tex