Search code examples
iislibreoffice

Permission issues on temporary file creation running LibreOffice soffice.exe from IIS AppPool


I'm running soffice.exe from an IIS site with AppPool identity to convert a docx to pdf.

Somehow, it tries to create files in C:/Windows/LibreOffice, which causes an access error. What could cause this behavior?

This is the code part:

string libreOfficePath = @"C:\Program Files\LibreOffice\program\soffice.exe";
string docxPath = @"D:\docs\abc.docx";
string pdfOutputPath = @"D:\docs\out";
string logPath = @"D:\docs\logs";

string arguments = "--headless --convert-to pdf " + docxPath + " --outdir " + pdfOutputPath;

var startInfo = new ProcessStartInfo
{
    FileName = libreOfficePath,
    Arguments = arguments,
    RedirectStandardOutput = true,
    RedirectStandardError = true,
    UseShellExecute = false,
    CreateNoWindow = true,
    WorkingDirectory = @"C:\Program Files\LibreOffice\program"
};

These are my settings: pic1 I've given the app pool permissions for these folders.

If I set the app pool identity to localsystem, the command does the job and creates the pdf.

If I set to apppool identity, the process tries to create temp files in C:/Windows/LibreOffice, which obviously fails.

App monitor logs this: pic2

This is the command line it gets:

"C:\Program Files\LibreOffice\program\soffice.exe" "--headless" "--convert-to" "pdf" "D:\docs\abc.docx" "--outdir" "D:\docs\out" "-env:OOO_CWD=2C:\\Program Files\\LibreOffice\\program"

Solution

  • After a couple hundred attempts, specifying the folder with:

    -env:UserInstallation=
    

    solved the issue.