vbscripthelper
Utility functions for reading VBScript objects in D. License:Boost License 1.0. Authors:
Denis Shelomovskij
- auto getObject(T)(string obj);
- Creates VBScript object obj using Windows Script Host cscript and transfers
requested properties into returned D object of type T through a temp file.
Requested properties are determined case insensitive by type T.
Every struct in T (including T if it is a struct)
is either value or reference struct. There can be only pointers for reference structs
and no pointers for value structs. Reference structs are used when self-referencing is needed
or if and object can be duplicated otherwise and we don't want it.
Example:
// Let's use Windows Update Agent (WUA) API // http://msdn.microsoft.com/en-us/library/windows/desktop/aa387292(v=vs.85).aspx struct UpdateIdentity { int RevisionNumber; string UpdateID; } struct Update { bool AutoSelectOnWebSites; UpdateIdentity Identity; string[] KBArticleIds; string Title; } enum searcher = `CreateObject("Microsoft.Update.Session").CreateupdateSearcher()`; enum obj = searcher ~ `.Search("IsAssigned=1").Updates`; auto updates = getObject!(Update[])(obj); import std.stdio; writefln("`IsAssigned=1` updates count: %s", updates.length); foreach(i, u; updates) writefln("#%s: %s rev. %s\nKBArticleIds: %s\n%s\n", i, u.Identity.UpdateID, u.Identity.RevisionNumber, u.KBArticleIds, u.Title); // If self-referencing is needed e.g. struct Update2 { Update2*[] BundledUpdates; string Title; } // Note: we can't use Update2[] because Update2 is a reference struct auto res2 = getObject!(Update2*[])(obj); auto updates2 = res2.obj, updatesRefs = res2.refs[0]; assert(updates2.length == updates.length); assert(updatesRefs.length >= updates2.length); import std.range; foreach(u, u2; zip(updates, updates2)) assert(u.Title == u2.Title);
