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 :)