roger21

hello,

I know it is not good programming to use Word in service mode but that wasn't my idea at the first place and i am actually facing one of the problems discribed in the KB257757 documentation.

But first an other problem:

I would like to set up specific TMP and TEMP directories for the Word instances, i used _putenv just before the CreateInstance("Word.Application.11"); statement and it works just fine when the application is running in user mode but in service mode the Word instances keep using the global /WINDOWS/TEMP directory. So any explanation and solution to force word instances to use my specific temporary directory would be greatly welcome.

My specific "Word used in service mode" problem is Word obviously displaying a popup windows during the process and that stops the process (until it is killed by a word process cleanner thread of mine) i tried to check the box "Allow service to interact with desktop" or use the current user instead of the "SYSTEM" user but i doesn't display its popup window at all (I am using the computer in "remote desktop connection" i wonder if it plays a role). I'm quite sure it is a popup window because i already have a similar problem, i performed to recreate the probleme in user mode and get the popup windows and added some line in my code to avoid the case, but there, i just can't perform to recreate the problem in user mode.

any help would be welcome

thanxs


Re: Visual C++ General Word used in service mode

Ramkrishna Pawar

If launched in some user's context, it will use the environment set for that user, when set as a service, it will always use the global environment.

How have you set it as a service Are you running it as a child process under your custom service




Re: Visual C++ General Word used in service mode

roger21

hi, thanx for your answer,

To set the service i used the Win32's CreateService function giving the path and name of my application then i launch it manualy.

CreateService(myHSCManager,
serviceName,
serviceName,
SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS,
SERVICE_DEMAND_START,
SERVICE_ERROR_NORMAL,
servicePath,
NULL,
NULL,
NULL,
NULL,
NULL);


as you can see i don't use a specific user wich could be my solution if i understood you well.




Re: Visual C++ General Word used in service mode

roger21

Actually i realize i was not really acurate about my application, i do not launch Word as a service, I launch an application (as a service) wich launch Word so there is actually two distinct execution context.

But what is bugging me is when i launch my application (which set the TEMP and TMP environment variables with _putenv) from a console the word process use those just set TMP and TEMP directories and when i launch my application as a service the Word process use consistently the global %TMP% and %TEMP% directories.

I also tried to set my service as a specified user (from the service properties in the mmc services list) but the word process keep using the global %TMP% and %TEMP% directories. Is there a way to build a service with launched process which stay in a specified execution context not being catched by the SYSTEM user






Re: Visual C++ General Word used in service mode

Ramkrishna Pawar

You should launch word process in that user's (Or logged in users) context.

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=2098101&SiteID=1






Re: Visual C++ General Word used in service mode

roger21

actually i launch word with

word::_ApplicationPtr myApp;
myApp.CreateInstance("Word.Application.11");

that of course enable me to have full acces of the application object how can i specify a user with that




Re: Visual C++ General Word used in service mode

Ramkrishna Pawar

If you launch Word in user's context and then use the CreateInstance, I think it will connect to running process, that way you will ahve automation server in user's context.






Re: Visual C++ General Word used in service mode

roger21


hmm i'm not sure what you mean about launching Word in user's context, how do i do that

the create instance is the way i launch word




Re: Visual C++ General Word used in service mode

Ramkrishna Pawar

You need to open the token of any process launched under that user's context and use it to launch your process using CreateProcessAsUser.

Please refer to the link in my earlier post, it has some sample code for it too.

OpenProcessToken Function (Windows)

CreateProcessAsUser Function (Windows)




Re: Visual C++ General Word used in service mode

roger21

just to be sure of what you are talking about before I go further with your advices; currently I use the method CreateInstance of the object Word::_ApplicationPtr I get the Word object which i can use to create documents, get document objects and works with this document objects. Wil i be able to do the same if I launch Word as a process




Re: Visual C++ General Word used in service mode

Ramkrishna Pawar

Yes, think of following, you manually invoke word under current user's context, and then use CreateInstance in your service, what will happen So it will be same with the code used to launch word in user's context.






Re: Visual C++ General Word used in service mode

roger21

Ok so ui tried and it didn't work (at all), the createprocessasuser create a word process as my specified user and the createinstance create a second word process as system, my code of course use the word object created by createinstance and the first word process does nothing.