0

Batch File (that calls a vbs) will run in Task Scheduler when logged in but not when logged out

Assumptions:

I've scoured the internet and exhausted my search on StackOverflow before making this post. There have been many good ideas I have attempted - none of which yielded the desired result.

Using full UNC path in Actions.

Utilizing Start In option

Not using trailing '\' or "Path" in Start in option in Actions

Batch file executes when executed manually or run from Task Scheduler when "Run only when user is logged on" radio button is checked but not when not logged in.

The job is running (or not, in my case) on my box.

Simple batch file:

@echo off

for /R "C:\FilePath" %%f in (*.docx) do (
   call C:\FilePath\convert.vbs %%f C:\FilePath\output\%%~nf.pdf 
)

VBS.

Convert

Sub Convert
   Call docToPdf(WScript.Arguments(0),WScript.Arguments(1))
End Sub

Function docToPdf(byVal docInputFile, byVal pdfOutputFile )
    Dim wordApplication
    Dim wordDocument
    Dim wordDocuments
    Const wdDoNotSaveChanges = 0
    Const wdFormatPDF        = 17

Set wordApplication = CreateObject("Word.Application")

Set wordDocuments = wordApplication.Documents

wordApplication.WordBasic.DisableAutoMacros

Set wordDocument = wordDocuments.Open(docInputFile)

wordDocument.SaveAs pdfOutputFile, wdFormatPDF

wordDocument.Close WdDoNotSaveChanges
wordApplication.Quit WdDoNotSaveChanges

Set wordApplication = Nothing
End Function

This combination converts docx files and converts them to PDF files. It works perfectly but I do not want to leave a user logged onto my server for it to run. I'm open to a solution for it to work in the Task Scheduler or another solution that will run there.

*** I'm not exactly sure why but creating C:\windows\System32\config\systemprofile\Desktop from command line (as administrator) allows this file to execute in the scheduler even if it is set to run when user is logged on or not.

My new problem is that I can get it to run on my personal box (Windows 10) but not on a 2012R2 server.....

4
  • 2
    cscript convert.vbs seems to be a better option to call a vbs
    – user6250760
    Aug 29, 2017 at 3:22
  • Agreed. I've tested with this syntax as well. There have been many iterations. Lol. Either way, it runs the same in the scheduler. Only when the user is logged in.
    – Joshua_B
    Aug 29, 2017 at 14:03
  • Asking all the silly questions now: 1) You mention what happens when "Run only when user is logged on" is checked; how about unchecked? 2) Is it possible you have a security setting or domain rule which denies running when user is not logged on (perhaps the equivalent of a "This account cannot run as batch" sort of setting?) 3) Have you confirmed the credentials of the Task Scheduler job? (yeah, that's a wild left field thing but just fishing here) Aug 29, 2017 at 21:57
  • Sure. Hard to help with an issue if you don't have all of the details. The "Run only when user is logged on" and the "Run whether user is logged on or not" are a radio button group so either one or the other must be selected. the job runs when the "Run only when user is logged on" is selected but not when "Run whether user is logged on or not" is selected. As far as I can tell, there are no security settings or Task Scheduler credentials that would prohibit the job to run. I'll edit the post to add the VBS it calls so everyone can have a full picture of what the issue is.
    – Joshua_B
    Aug 30, 2017 at 1:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.