nil.enroll(aetheric_username, quantum_class_id) (adric) wrote,
nil.enroll(aetheric_username, quantum_class_id)

  • Location:
  • Mood:

WMI, IIS, CIM and other cursewords

Finally, after hours of reading through mind-numbingly overcomplicated documentation about the incredible plural architectures for Windows system management (not that I wanted to know any of that, mind you) and their various benighted APIs and tools ...

I present, the answer, or at least the kernel of one:

// Make connections to WMI, to the IIS namespace on MyMachine, and to the Web service. 
var locatorObj = new ActiveXObject("WbemScripting.SWbemLocator"); 
var providerObj = locatorObj.ConnectServer("MyMachine", "root/MicrosoftIISv2"); 
var serviceObj = providerObj.Get("IIsWebService='W3SVC'"); 
// Build binding object, which is a required parameter of the CreateNewSite method. 
// Use the SpawnInstance WMI method since we are creating a new instance of an object. 
var Bindings = new Array(); 
Bindings[0] = providerObj.get("ServerBinding").SpawnInstance_(); 
Bindings[0].IP = ""; 
Bindings[0].Port = "8383"; 
Bindings[0].Hostname = ""; 
// Create the new Web site using the CreateNewSite method of the IIsWebService object. 
try { 
var strSiteObjPath; 
strSiteObjPath = serviceObj.CreateNewSite("MyNewSite", Bindings, "C:\\Inetpub\\Wwwroot"); 
catch(e) { 
WScript.Echo("*** Error Creating Site: " + e + " " + e.Number + ", " + e.Description + " ***"); 
// strSiteObjPath is in the format of IIsWebServer='W3SVC/1180970907' 
// To parse out the absolute path, W3SVC/1180970907, use the SWbemObjectPath WMI object. 
var objPath = new ActiveXObject("WbemScripting.SWbemObjectPath"); 
objPath.Path = strSiteObjPath; 
strSitePath = objPath.Keys.Item(""); 
// var some properties on the root virtual directory which was created by CreateNewSite. 
var vdirObj = providerObj.Get("IIsWebVirtualDirSetting='" + strSitePath + "/ROOT'"); 
vdirObj.AuthFlags = 5; // AuthNTLM + AuthAnonymous 
vdirObj.EnableDefaultDoc = true; 
vdirObj.DirBrowseFlags = 0x4000003E; // date, time, size, extension, longdate 
vdirObj.AccessFlags = 513; // read, script 
vdirObj.AppFriendlyName = "Root Application"; 
// Save the new settings to the metabase 
// CreateNewSite does not start the server, so start it now. 
var serverObj = providerObj.Get(strSiteObjPath); 
WScript.Echo("A New site called MyNewSite was created with the path and unique site identification number of " + strSitePath);

Tags: scripting, windows

  • To not quote Ms. Spears...

    Oops? I managed to avoid keeping this one only by sheer force of willpower, and I could tell she was disappointed. *long drawn out sigh* We…

  • Hopped onto SL tonight and got some chat in, sideways

    ... at a funny angle with an @adj_list av I've 'known' for ages but don't know at all. We got a chance to talk for the first time in ages (or…

  • SL Renewal? Downgrade to Free

    Nets me a form to fill out: "You've decided to discontinue land ownership in Second Life, and it would help us a lot to understand why."…

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded