1

Hi All,

I have an application (windows service/C#) which starts EXCEL and POWERPOINT and copies the data between these two applications using system clipboard.
Application runs on a server with multiple active terminal sessions.
Office apps by default start in a session with lowest session ID.

COM objects

I use COM objects to communicate between ms-service and office apps. Following code is an example of how I run EXCEL.

xlApp = new Microsoft.Office.Interop.Excel.Application();  
xlWorkBook = xlApp.Workbooks.Open("path_to_my_file", 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);

Multi Threading - parallel sessions

ATM the application is running on single thread mode. I'm planning to run 2 simultaneous threards... the problem is that I have only 1 clipboard available for communication purposes. In order to get another one, I'm planning to run the whole application on 2 separate windows sessions. In that case I would have 2 separate single-threaded solutions. There will be 2 copies of the service, running their own office apps and I'll have 2 separate clipboards for my use.

Problem

One matter remains unsolved - I have no idea how to force these office apps to run on different user sessions. From what I see, they are always running in a sesison with lowest ID.

I've found similar question - On Terminal Server, how does a service start a process in a user's session? , however, running a process is not that similar to running office application via COM objects.

EDIT : I've noticed that if I open the EXCEL not from WINDOWS SERVICE but from WINDOWS FROMS APPLICATION, the EXCEL behaves differently. It no longer starts under user session with lowest ID, instead it opens itself on the same account where WINDOWS FORMS APP is running. That somehow solves my issue and I'll be able to run 2 parallel processes :)

Community
  • 1
  • 1
  • Can you move the "core" code (open applications, copy) to another process? You may start that process with different credentials. – Adriano Repetti Mar 12 '12 at 11:51
  • Yes, I can, however, It wouldn't change a thing. Excel starts on default session, because I have no way to specify otherwise. Even if I move the code to another thread, it will open 2 excels under the same windows account (lowest session ID), that means I'll have only 1 clipboard to use, where I need to have 2 separate clipboards for this solution to work. – adrian.krzysztofek Mar 12 '12 at 13:09
  • I do not mean to start a new thread but a new process for the whole stuff, you may run the process with different credentials (user). But if you don't want/can't change... – Adriano Repetti Mar 12 '12 at 13:21
  • Sorry, my bad :) Well, That's what I was planing to do anyway. To run different process (a copy of the 1st one), however, that's what excel is doing is beyond my code. Let's say that I run my "core" under "user1" credentials, and then run another instance/copy as another proces under "user2". If a session with lowest ID belongs to "user3", both excels will open on "user3" session. They will just pop up on his screen and when I use .CopyPicture() from process, which is running under "user1", user3's clipboard is used for that. I hope that makes sense :) – adrian.krzysztofek Mar 12 '12 at 13:49

1 Answers1

0

Answer:

Migrate solution from Windows Service to Windows Forms application, as its default behaviour is different. It starts Excel on current session - the one on which application is running itself.