How to get application pool via script? | Minicoder

'Description:
'    Function to get the IIsApplicationPools Object.
'Input: 
'    None.
'Output:
'    An IIsApplicationPools Object.
'Throw Exception When:
'    Cannot Get IIsApplicationPools Object.

public function get_IIS_Pools
    on error resume next
        set get_IIS_Pools = GetObject("IIS://localhost/W3SVC/AppPools")
        if (Err.Number <> 0) Then
            on error go to 0
            Err.Raise 10000, "get_IIS_Pools", "Unable get the IISApplicationPools object"
        else
            on error go to 0
        end if
end function

If you can not understand above code sample, please refer to another article Quick Start : IIS | Minicoder

If you want get specific IISApplicationPool object using the name of the application pool instead of IISApplicationPools, Please see

'Description:
'    Function to get the IIsApplicationPool Object using the name of the application pool.
'Input:
'    appPoolName: the name of the application pool
'Output: 
'    A IIsApplicationPool Object with the given name.
'Throw Exception When:
'    Cannot get IIsApplicationPool Object of the specified application pool.

public function get_IIS_Pool(appPoolName)
    on error resume next
        set get_IIS_Pool = GetObject("IIS://localhost/W3SVC/AppPools/" & appPoolName)
    if (Err.Number <> 0) Then
        on error goto 0
        Err.Raise 10000, "get_IIS_Pool", "Unable get IISApplicationPool object by using application pool name" & appPoolName
    else
        on error goto 0
    end if
end function

You can also use above code to check the existence of application pool with given name

'Description:
'    Function to Check the existence of the application pool with the given name.
'Input:
'    appPoolName: the name of the application pool
'Output: 
'    Exist -> True.  
'    Non-exist -> False.
'Throw Exception When: 
'    Never.

public function check_IIS_Pool(appPoolName)
    on error resume next
        get_IIS_Pool(appPoolName)
        if (Err.Number <> 0) then
            check_IIS_Pool = false
        else
            check_IIS_Pool = true
        end if
    on error goto 0
end function

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章