Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Script doesn't work when logged off

$
0
0

I have a very basic PS script that converts Word Doc to PDF. I have a folder/queue set up where the DOC/DOCX files get placed. Then at 2am I run the script and the files get converted to PDF. This works fantastic, as long as the server is logged in and the task scheduler is set to "run only when user is logged in". If I select the other option. "run whether user is logged in or not", the script will run but the conversion never happens. I spoke with Microsoft support and so far the only thing they can come up with is that, since it uses Word to do the conversion, it needs to have an open session.

So this brings up my questions...

Does it make sense, what I'm being told?

Is there another way to accomplish this?

If there is no way, to do this logged off, is there a script I can run before this one, to log the user back in?

Here is a copy of the script I'm using:

$documents_path = 'F:\DOCtoPDF'

$word_app = New-Object -ComObject Word.Application

# This filter will find .doc as well as .docx documents
Get-ChildItem -Path $documents_path -Filter *.doc? | ForEach-Object {

    $document = $word_app.Documents.Open($_.FullName)

    $pdf_filename = "$($_.DirectoryName)\$($_.BaseName).pdf"

    $document.SaveAs([ref] $pdf_filename, [ref] 17)

    $document.Close()

}

$word_app.Quit()

ps winword | kill

Thanks for the help


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>