Page 1 of 1

Closing ServiceManager

Posted: Thu Dec 30, 2010 11:08 am
by lunter

Code: Select all

Set objServiceManager= WScript.CreateObject("com.sun.star.ServiceManager")
Is any method to close objServiceManager ??

Code: Select all

objServiceManager.Close() // thows exeption
I must stop soffice.bin task on exit.

Re: Closing ServiceManager

Posted: Thu Dec 30, 2010 1:44 pm
by rudolfo
See the API documentation for ServiceManager. As far as I understand this the service implements the XComponent interface, so:

Code: Select all

objServiceManager.dispose()
seems to be more promising. Not tested by me. But see what you can achieve with it.
 Edit: My signature is a standard signature not an advice for you. If you are using Wscript.CreateObject your language is definitely VB Script. And Visual Basic would be the correct phrase for the scripting language that you are using. 

Re: Closing ServiceManager

Posted: Fri Dec 31, 2010 1:20 pm
by rudolfo
DId a little test, because the API didn't sound like dispose() would really do something with a real impact. XComponent applies to any UNO object and the .dispose() method should automatically be called when the object goes out of scope or is destroyed by the garbage collector (typically both garbage collectors, the one of the scripting language and the internal one implemented in the C++ core).
My test with a simple do-nothing script

Code: Select all

Set objServiceManager= WScript.CreateObject("com.sun.star.ServiceManager")
objServiceManager.dispose()
Set objServiceManager = Nothing
doesn't throw a runtime error, but the processes soffice.exe and soffice.bin are still up.

Thinking again on this it might well be that the CreateObject("com.sun.star.ServiceManager") doesn't to the same thing as simply starting OpenOffice from the desktop. More something like the "-remote" thing to start it as a server that allows socket connections. At least the commandline that is used to start it from the VB Script is:

C:\Programme\OpenOffice.org-3\program\soffice.exe -nodefault -nologo -Embedding

The default link in the Startmenu has no parameters, simply soffice.exe.
Note that the situation could be completely different if the quicklauncher is running. It is off on my system.

Re: Closing ServiceManager

Posted: Fri Dec 31, 2010 7:50 pm
by B Marcelly
Hi,
This closes OpenOffice from VBScript or VBA

Code: Select all

Set StarDesktop = objServiceManager.createInstance("com.sun.star.frame.Desktop")
StarDesktop.terminate

Re: Closing ServiceManager

Posted: Sat Jan 01, 2011 3:08 pm
by rudolfo
Thanks, Bernard. This is actually doing the trick. After StarDesktop.terminate both processes are gone from the list of running processes in the task manager. The intersting part is that this method of the "com.sun.star.frame.Desktop" service does not only "destroy" the own object, but also the "parent" ServiceManager object. An additional call to
objServiceManager.dispose()
gives me an error message in something that is close to perfect German:
Laufzeitfehler in Microsoft VBScript
Der Remoteservercomputer ist existiert nicht oder ist nicht verfügbar: 'dispose'

On second thought this is not really surprising, because if there is not OpenOffice process running there is no longer a scope for any of the UNO instances where they could live.