fredmartinmaine
IS-IT--Management
' ChildScript.vbs
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection
objSelection.TypeText "Hello World"
objDoc.SaveAs "test.pdf", 17 ' 17 = PDF
objDoc.Close 0
The above code creates a Word doc and saves it as a PDF file, then closes Word without saving the Word doc.
Works perfectly when run interactively by a user. It doesn't prompt user for anything. Just runs and created the PDF.
When the script is a scheduled task, though, same machine and same user, it always hangs (doesn't crash) on the SaveAs call.
Details of the scheduled task:
A parent vbscript is scheduled, the action is:
Program: C:\Windows\System32\cscript.exe
Argument: "C:\Windows\test\ParentScript.vbs"
In that parent script a call is made to run the child script:
objShell.Run("C:\Windows\test\ChildScript.vbs", 0, TRUE) ' windows style 0, wait for return TRUE
I do not believe this is anything to do with scheduler, the objShell,run, and so on. I have other scripts running in this exact way that are working, creating Excel docs and XML files.
What's different here is the MS Word SaveAs bit. Why would it work interactively but not as a scheduled task?
Stumped.
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection
objSelection.TypeText "Hello World"
objDoc.SaveAs "test.pdf", 17 ' 17 = PDF
objDoc.Close 0
The above code creates a Word doc and saves it as a PDF file, then closes Word without saving the Word doc.
Works perfectly when run interactively by a user. It doesn't prompt user for anything. Just runs and created the PDF.
When the script is a scheduled task, though, same machine and same user, it always hangs (doesn't crash) on the SaveAs call.
Details of the scheduled task:
A parent vbscript is scheduled, the action is:
Program: C:\Windows\System32\cscript.exe
Argument: "C:\Windows\test\ParentScript.vbs"
In that parent script a call is made to run the child script:
objShell.Run("C:\Windows\test\ChildScript.vbs", 0, TRUE) ' windows style 0, wait for return TRUE
I do not believe this is anything to do with scheduler, the objShell,run, and so on. I have other scripts running in this exact way that are working, creating Excel docs and XML files.
What's different here is the MS Word SaveAs bit. Why would it work interactively but not as a scheduled task?
Stumped.