http://adndevblog.typepad.com/autocad/2 ... table.html
Code: Select all
#NoEnv
#SingleInstance Force
SetBatchLines, -1
Ptr := A_PtrSize ? "Ptr" : "UInt"
UPtr := A_PtrSize ? "UPtr" : "UInt"
TestROT()
Return
CreateBindCtx() {
DllCall("ole32.dll\CreateBindCtx", UInt, reserved, UPtr, prot)
Return prot
}
GetRunningObjectTable() {
DllCall("ole32.dll\GetRunningObjectTable", UInt, reserved, UPtr, prot)
Return prot
}
; Get all running instance by querying ROT
GetRunningInstances(progIds)
{
static Type := ComObjCreate( "System.Runtime.InteropServices").ComTypes
static clsIds := {}
; get the app clsid
for progId in progIds
{
type := Type.GetTypeFromProgID(progId)
if(type != "")
clsIds.Insert(type.GUID)
}
; get Running Object Table ...
Rot := GetRunningObjectTable()
if (Rot = "")
return ""
; get enumerator for ROT entries
monikerEnumerator := Rot.EnumRunning._NewEnum()
instances := {}
; go through all entries and identifies app instances
while (monikerEnumerator.Next(1, monikers, pNumFetched) = 0)
{
bindCtx := CreateBindCtx()
if (bindCtx = "")
continue
monikers[0].GetDisplayName(bindCtx, "", displayName)
for clsId in clsIds
{
if (displayName.IndexOf(clsId) > 0)
{
ComObject := Object()
Rot.GetObject(monikers[0], ComObject)
if (ComObject = "")
continue
instances.Insert(ComObject)
break
}
}
}
return instances
}
TestROT()
{
; Look for acad 2009 & 2010 & 2014
progIds := ["AutoCAD.Application.17.2","AutoCAD.Application.18","AutoCAD.Application.19.1"]
instances = GetRunningInstances(progIds)
for acadObj in instances
{
try
{
; do some stuff ...
}
catch
{
}
}
}