Closing ServiceManager

Creating a macro - Writing a Script - Using the API

Closing ServiceManager

Postby lunter » Thu Dec 30, 2010 11:08 am

Code: Select all   Expand viewCollapse view
Set objServiceManager= WScript.CreateObject("com.sun.star.ServiceManager")


Is any method to close objServiceManager ??

Code: Select all   Expand viewCollapse view
objServiceManager.Close() // thows exeption


I must stop soffice.bin task on exit.
OOo 3.3.X on MS Windows 7
lunter
 
Posts: 28
Joined: Fri May 29, 2009 9:16 am

Re: Closing ServiceManager

Postby rudolfo » Thu Dec 30, 2010 1:44 pm

See the API documentation for ServiceManager. As far as I understand this the service implements the XComponent interface, so:
Code: Select all   Expand viewCollapse view
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. 
Last edited by rudolfo on Fri Dec 31, 2010 1:20 pm, edited 1 time in total.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
rudolfo
Volunteer
 
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Re: Closing ServiceManager

Postby rudolfo » Fri Dec 31, 2010 1:20 pm

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   Expand viewCollapse view
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.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
rudolfo
Volunteer
 
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Re: Closing ServiceManager

Postby B Marcelly » Fri Dec 31, 2010 7:50 pm

Hi,
This closes OpenOffice from VBScript or VBA
Code: Select all   Expand viewCollapse view
Set StarDesktop = objServiceManager.createInstance("com.sun.star.frame.Desktop")
StarDesktop.terminate
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
B Marcelly
Volunteer
 
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Closing ServiceManager

Postby rudolfo » Sat Jan 01, 2011 3:08 pm

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.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
rudolfo
Volunteer
 
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 0 guests