1

I'm trying to run Word from cscript witch is runned out from windows service under LOCAL SYSTEM account.

cscript is simple. Something like this:

Option Explicit

On Error Resume Next

SaveWordAsPDF

Sub SaveWordAsPDF() 


 Dim objWord
 Dim objDocument

 if WScript.Arguments.Count = 0 then
   WScript.Echo "Missing parameters"
end if

 Set objWord = CreateObject("Word.Application")
 'objWord.Visible = True
 objWord.WordBasic.DisableAutoMacros
 Set objDocument = objWord.Documents.Open(WScript.Arguments.Item(0), 0, True) 
 WScript.Sleep 5000
 objDocument.SaveAs WScript.Arguments.Item(1), 17

 objDocument.Close FALSE
 objWord.Quit
End Sub 

I'm getting an error "Word could not create the work file. Check the Temp environment variable". All answers from this Automating MS Word in Server 2012 R2 topic doesn't help.

Word 2013 x64 Windows Server 2012 R2 x64.

Community
  • 1
  • 1
Okapist
  • 116
  • 11
  • If you are going to automate anything that has to do with Word (or Excel, or any other Office app), I strongly suggest using [the official SDK for .NET](https://www.microsoft.com/en-us/download/details.aspx?id=30425). You will save a lot of work, your code will be easier to maintain, and your application will probbly do whatever it is it does in much less time whenever you call it. – Geeky Guy Mar 03 '17 at 16:24
  • Also the "Temp environment variable" has to do with your system configuration. You can access the environment config by going to "Computer -> Properties -> Advanced System Settings". Check whether your path variable includes a temp folder or something. – Geeky Guy Mar 03 '17 at 16:27
  • Try setting a machine-wide TEMP variable in Control Panel...System...Advanced System Setting..Envrionment Variables.. Even if you get past this issue, I'm still concerned that it won't be possible to bring up a GUI window under the Local System account. – sevzas Mar 03 '17 at 16:34
  • OpenXML DSK doesn't allow all functionality what i needed. Convert to pdf it's only one example which is not allowed by OpenXML SDK. I set TEMP and TMP environment variables. But nothing changed. – Okapist Mar 03 '17 at 17:09
  • This is [not a supported scenario](https://support.microsoft.com/en-us/help/257757/considerations-for-server-side-automation-of-office): *"Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment."* – IInspectable Mar 03 '17 at 18:03
  • Since you are using "objDocument.SaveAs" I assume you need to open Word to convert documents to a different format. Check for other software that can convert Word documents. – Sam Hobbs Mar 06 '17 at 23:24

0 Answers0