开发者

IIS 6.0: what is the WMI equivalent of "Convert Folder To Application"?

开发者 https://www.devze.com 2022-12-24 11:52 出处:网络
Basically, imagine you need to automate these steps: Open Internet Information Services. Find the web site, find the folder, right click the folder and select properties.

Basically, imagine you need to automate these steps:

  1. Open Internet Information Services.
  2. Find the web site, find the folder, right click the folder and select properties.
  3. Click the Directory folder.
  4. Under Applications settings, click the Create button. Th开发者_如何学JAVAe application is now created. Click OK to finish.

(click for a pictoral walkthru)

My end goal is Powershell, but answers that use JScript or VB.NET or whatever are fine too.

Bonus points if the same code works against an IIS7 application running in 6.0 Compatibility Mode.


I've used this VBScript successfully. YMMV but at least it's a starting point.

' set a few constants
const CreateNewApplicationPool = true
const UseExistingApplicationPool = false

' Load the Metabase entry if the target directory does exist
Set IISWebDirObj = GetObject("IIS://" & objServer & "/W3SVC/" & objSiteID & "/Root/" & objApp)

if Err.Number <> 0 then
    Err.Clear
    ' Create the Metabase entry if the target directory does NOT exist
    Set IISWebDirRootObj = GetObject("IIS://" & objServer & "/W3SVC/" & objSiteID & "/Root")
    Set IISWebDirObj = IISWebDirRootObj.Create("IISWebDirectory", objApp)
end if

' Assign an existing app pool to the target directory
' Try AppCreate or Appcreate2 to create the app pool at the same time
'  or try using CreateNewApplicationPool for last parameter
IISWebDirObj.AppCreate3 2, objSvcPool, UseExistingApplicationPool

' set the name so it doesn't show up as: Default Application
IISWebDirObj.AppFriendlyName = objSvcPool
IISWebDirObj.SetInfo

' refresh the object in memory so we can change the app pool
IISWebDirObj.GetInfo  
IISWebDirObj.AppPoolId = objSvcPool
IISWebDirObj.SetInfo


Check IIS6 Automation.

Edited to add

As requested: here.


This isn't exactly what you're looking for - they actually created a virtual directory and then make it an application. But the approach - using ADSI from powershell - should work for IIS 6/7 and allow you to turn an existing directory into an application:

http://arcware.net/creating-iis-applications-with-powershell/

The AppCreate2 (and SetInfo) call is what turns the virtual directory into an application. You could call this on a regular directory, too.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号