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

  • And then..

    So much happened over the weekend (already) (mostly at that party or around it) that it's going to take me months to process all of it and weeks to…

  • Gaming, Fun, and Bouncy Silliness

    Occams_Razor(@post.prev.memeplex) => 'Have them come over to your house, stupid.' Game was effectively sabotaged by my lack of preparation for…

  • Thanks so much!

    Thank you all for the cool and thoughtful gifts! I am grateful and quite embarrassed.. The spread: A clean house! some very…

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded