'/////////////////////////////////////////////////////////////////////////////////

' Author: SYO

' Copyright (c) 2014

'

' Purpose: Build a COM+ Application (aka ScriptEZ_APIWoW) under Windows 64 bit

' in order to make ScriptEZ.API object usable from within 64 bit VBScript/JScript

' files and so on

'

'/////////////////////////////////////////////////////////////////////////////////

 

AppName = "ScriptEZ_APIWoW"

ComponentPath = Replace(WScript.ScriptFullName,WScript.ScriptName,"ScriptEZWoW.dll")

    

' Get the local COM+ catalog

Dim Catalog ' As COMAdmin.COMAdminCatalog

Set Catalog = CreateObject("COMAdmin.COMAdminCatalog") 'New COMAdmin.COMAdminCatalog

Catalog.Connect ""

 

' Get the Applications collection

Dim Apps ' As COMAdmin.COMAdminCatalogCollection

Set Apps = Catalog.GetCollection("Applications")

Apps.Populate

   

For i=0 to Apps.Count-1

  ' if already installed, popup a message and run Component Service Console

  If Apps.Item(i).Name = AppName Then

   ' instantiating ScriptEZ.API thru COM+ Application (dllhost.exe) and

   ' call its MsgBox function

   Set ScriptEZ = CreateObject("ScriptEZ.APIWoW")

   r = ScriptEZ.MsgBox(,"{ScriptEZ.APIWoW} object already installed !",vbInformation)

       

   ' start Component Service Console

   Set WshShell = CreateObject("WScript.Shell")

   WshShell.Run "dcomcnfg.exe"       

   Wscript.Quit

  End If

Next

 

' Create a new Application object

Dim App ' As COMAdmin.COMAdminCatalogObject

Set App = Apps.Add()

 

' Set new Application's name

App.Value("Name") = AppName

App.Value("ConcurrentApps") = 7 ' pool size

 

' Save the new Application

Apps.SaveChanges

 

' Install the COM .dll into the new Application

Catalog.InstallComponent AppName, ComponentPath,"",""

 

' Adding Roles

Set roles = Apps.GetCollection("Roles",App.key)

roles.Populate

Dim role

Set role = roles.Add()

role.Value("Name") = "ScriptEZ.APIWOW"

roles.SaveChanges

   

Set WshNetwork = WScript.CreateObject("WScript.Network")

Set users = roles.GetCollection("UsersInRole",role.key)

users.Populate

set user = users.Add()

' on the name of current user

user.Value("User") =  WshNetwork.ComputerName + "\" + WshNetwork.UserName

users.SaveChanges

   

' the Application

MsgBox "{ScriptEZ.APIWoW} object installed successfully as COM+ Application !" , _

       vbInformation

' instantiating ScriptEZ.API thru COM+ Application (dllhost.exe) and

' call its Echo and Sleep function

Set ScriptEZ = CreateObject("ScriptEZ.APIWoW")

ScriptEZ.Echo " . Hello World !" + vbLF + _

              " . Windows On Windows Technology (WoW) "  + vbLF + _

              "   makes me now happy with 64 bit apps and scripts world...."

ScriptEZ.Sleep 7000

   

' Cleanup Applications and Catalog....

Set App = Nothing

Set Apps = Nothing

Set Catalog = Nothing

Set role = Nothing

Set roles = Nothing

Set user = Nothing

Set users = Nothing

Set WshNetwork = Nothing