Archive for 5月 14th, 2012

  1. Hello, COM(VBScript) World!

    Posted on 5月 14th, 2012 by cx20

    COM(VBScript)

    COM(Component Object Model)はマイクロソフトの提唱するプログラム部品の仕様である。
    COM を用いて開発された部品であれば言語を問わず利用することができる。
    以下は VBScript による COM クライアント(実行時バインディング)の例となっている。

    ソースコード

    Option Explicit
     
    Const ssfWINDOWS = 36
     
    Call Main()
     
    Sub Main()
        Dim shell
        Set shell = CreateObject("Shell.Application")
        Dim folder
        Set folder = shell.BrowseForFolder( 0, "Hello, COM(VBScript) World!", 0, ssfWINDOWS )
        If ( Not folder Is Nothing ) Then
            Set folder = Nothing
        End If
        Set shell = Nothing
    End Sub

    実行方法

    C:¥> CScript hello.vbs

    実行結果

    +----------------------------------------+
    |Browse For Folder                    [X]|
    +----------------------------------------+
    | Hello, COM(VBScript) Wolrd!            |
    |                                        |
    | +------------------------------------+ |
    | |[Windows]                           | |
    | | +[addins]                          | |
    | | +[AppCompat]                       | |
    | | +[AppPatch]                        | |
    | | +[assembly]                        | |
    | |     :                              | |
    | |     :                              | |
    | |     :                              | |
    | +------------------------------------+ |
    | [Make New Folder]    [  OK  ] [Cancel] |
    +----------------------------------------+