Home of site/Basic Macro General

Macroの杜(LibreOffice Basic編 / General)


Appliaction Command実行
< 戻る

GBO-)[General]Shellコマンド
【picture】実行結果

最もシンプルなShellコマンドを利用した例です。

表示のStyleは第2引数で指定します。

 [ Style ]
  0	: Hidden(Focus)
  1	: Standard(Focus)
  2	: Min(Focus)
  3	: Max(Focus)
  4	: Standard
  6	: Min on the active window
 10	: Full

------------------------------ [ Sample Code ] ------------------------------


Sub Shell_1()
	Shell("notepad.exe",4,"c:\temp\oTextMacro.txt")	
End Sub

GBO-)[General]com.sun.star.system.SystemShellExecute
【Picture】実行結果

com.sun.star.system.SystemShellExecute Service

を利用する例です。

第3引数のFlag値はcom.sun.star.system.SystemShellExecuteFlagsを参照


Apache Openofficeのcom.sun.star.system.SystemShellExecuteのFlag値はこちら

------------------------------ [ Sample Code ] ------------------------------

Sub Shell_2()
	Dim oShellObj as Object
		oShellObj = createUnoService("com.sun.star.system.SystemShellExecute")
		oShellObj.execute("notepad.exe","c:\temp\oTextMacro.txt",0)
End Sub

GBO-)[General]ScriptForge / session
【Movie】実行結果

ScriptForgeライブラリのSession Service 

の RunApplication methodを利用する例です。

正常に起動すれば,Trueが返されます。
ファイルが存在しないなどの場合はFalseを返すのではなく、
例外が発生します。(ScriptForgeライブラリーがCrash)

また、Win11 64bit / LO7.5.7.1の環境では 
実行ファイル(notepad.exe)などを実行しようとしても
例外が発生します。(ScriptForgeライブラリーがCrash)
但し、関連つけられたファイルを開くことはできます。

session.RunApplication("Notepad.exe") : NG
session.RunApplication("Notepad.exe","c:\temp\test.txt")  : NG

以下は成功したコードです。

Sub SF_Session_RnApp()
	GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
	Dim session as Object
	Dim oRtn as boolean
		session = CreateScriptService("Session")
		oRtn = session.RunApplication("c:\temp\test.txt")
		msgbox(oRtn,0,"LO7.5.7.1")
End Sub

GBO-)[General]Windows Script Host

WSHのWScript.Shellを利用する例はこちら

inserted by FC2 system