Link to home
Start Free TrialLog in
Avatar of SCI_tech
SCI_techFlag for United States of America

asked on

.NET Launching MS Word Programmatically while on Terminal Server Session

Greetings,

Our goal is to launch MS Word programmatically to a file we just created and saved to disk using a .docx template.

The catch is: we have to do this through a Terminal Server (virtual) session - logged into Windows 2008 R2 !

However, while we CAN successfully create directories, create MS Word files, and write these to disk through the TS session...we are NOT able to LAUNCH MS Word on the TS session programmatically.  In other words, this "launch" portion is the only remaining part of the solution not yet working.

Furthermore, we ARE able to complete the launch using the following development environment / platform ...so we know the code "works"...:

 - Windows 7 Workstation
 - IE 9.0 Browser
 - Microsoft Visual Studio 2010
 - "Localhost" IIS App. Server
 - Connecting to MS SQL Server


...and YES, we can launch MS Word 'manually' through the TS Session navigating to and then opening the file we JUST CREATED using .vb code...so we know that MS Word is working (appropriate CAL's, etc.) on the TS...

[ANY IDEAS WOULD BE GREATLY APPRECIATED ...THANKS MUCH!]

THIS CODE WORKS LOCALLY IN THE DEV ENVIRONMENT, BUT NOT THROUGH A TERMINAL SERVER SESSION:

=================================================================
Private Sub LaunchWord  (_fileToLaunch As String)

        Try
            Dim WordApp As Word.Application = New Word.Application()
            Dim WordDoc As Word.Document = WordApp.Documents.Open(_fileToLaunch)
            WordDoc.Activate()
            WordApp.Visible = True

        Catch ex As Exception
            'Response.Write("An Error Occurred: " & ex.ToString())

        End Try

    End Sub
=================================================================
Avatar of Rick Hobbs
Rick Hobbs
Flag of United States of America image

Do you get any output?  Errors, etc?  Have you tried it in debug mode?
Avatar of SCI_tech

ASKER

Good question, here is error page on server with error tracking turned on...

Again, manually launching the outputted MS Word file DOES work...

Note:  "Line 389" is the end sub of the LaunchWord sub - referenced above - from my OutputWord class... ( and of course CreateDate is the next function)

Thanks!

================================================================
================================================================

Server Error in '/' Application.
--------------------------------------------------------------------------------

Could not load file or assembly 'office, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'office, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Source Error:


Line 387:        End Try
Line 388:
Line 389:    End Sub
Line 390:
Line 391:    Private Function CreateDate() As String
 

Source File: D:\FAS\App_Code\OutputWord.vb    Line: 389

Assembly Load Trace: The following information can be helpful to determine why the assembly 'office, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' could not be loaded.


WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

 

Stack Trace:


[FileLoadException: Could not load file or assembly 'office, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
   OutputWord.LaunchWord(String _fileToLaunch) in D:\FAS\App_Code\OutputWord.vb:389
   OutputWord.Petition_Approved_Letter(String _dfaNum, String _inputFileName, String _outputFileName) in D:\FAS\App_Code\OutputWord.vb:150
   Main.btnUpdatePetition_Click(Object sender, EventArgs e) in D:\FAS\Main.aspx.vb:1260
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3707

 


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
Main.btnUpdatePetition_Click(Object sender, EventArgs e) in D:\FAS\Main.aspx.vb:1260
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3707

Not only Terminal Services but using IIS!  IIS runs in a sandbox and is designed specifically to disallow launching of executables outside of the sandbox. Which application pool is this using?
Can IIS be configured to allow specific exe's?  Or, pass in some sort of pre-approved security token?
ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.