Sign in to follow this  
Followers 0
kheops31

WMI & IIS

7 posts in this topic

I will enum the websites on an IIS server that's is not my local WinXP...

I have found some code in the forum like this

$sMsg = "List of objects visible in IIS WMI Provider (//./root/MicrosoftIISv2):" & @CRLF
$oIIS = ObjGet("winmgmts://" & @ComputerName & "/root/MicrosoftIISv2")
;Get Virtural Directories
$n = 0
$sMsg &= @CRLF & "Virtual Directories (IISWebVirtualDir):" & @CRLF & @CRLF
$colVirDirs = $oIIS.ExecQuery ("Select * from IISWebVirtualDir")
For $oVirDir In $colVirDirs
    $n += 1
    $sMsg &= $n & ". Name: "
    $sMsg &= $oVirDir.Name & @CRLF
Next
MsgBox(64, "Test", $sMsg)

Why If i change "@ComputerName"

With "$Host" that will refer to a computer in my network

I receive always an error that it can't connect?

Share this post


Link to post
Share on other sites



WMI is easy.. all you need to do is set your hostname

$Host = "myhostname"

or

$Host = 'myhostname'

(it has to be a string type, so single or double quotes are required)

then it should work like you expect..

if not post a bit more code so we can take a look at it..


Share this post


Link to post
Share on other sites

maybe because its friday and more works crash my brain....i was sure that i made what u do...

WMI its eazy & FANTASTIC....

Share this post


Link to post
Share on other sites

i have changed @computername with "NameOfMyServer" withous sucess....

P.s: source of this code :

http://www.autoitscript.com/forum/index.php?showtopic=20456&hl=IIS

; W3Servers
; Applet to control virtual web servers in IIS5 or IIS6
; Author Bill Mezian, billmez - Jan06
;
#Include <GuiListView.au3>
#include <GUIConstants.au3>

_W3Servers()

Func _W3Servers()
Dim $RetMsg, $LastIndex, $dspIP,$GotServers, $Mval, $SLine, $SIndex, $w3svc, $Stitle, $Svip
Dim $Deny_Delete
Dim $DA

; pipe separated list of web sites not allowed to delete
; if $DAsites is = "" deletion will not be allowed and button
; will be inactive
Dim $DAsites = "Default Web Site|MyDomain.com|YourDomain.com"
$DA = StringSplit($DAsites, "|")
Dim $DAcount = UBound($DA) - 1
If Not $DA[$DAcount] Then
    $DAcount = 0
EndIf

; == GUI generated with Koda ==
Dim $WForm1 = GUICreate("WWW Server Control", 410, 385, -1, -1)
Dim $Label1 = GUICtrlCreateLabel("Click the Get Servers button to retrieve a list of virtual web servers.  Select the desired row and click on a service control buton to apply the action.", 30, 5, 350, 25)
Dim $WButton1 = GUICtrlCreateButton("Get Servers", 15, 295, 120, 21)
Dim $WButton2 = GUICtrlCreateButton("Refresh List", 145, 295, 120, 21)
Dim $WButton3 = GUICtrlCreateButton("Exit", 275, 295, 120, 21)
Dim $Group1 = GUICtrlCreateGroup("Service Control Buttons", 5, 322, 400, 53)
GUICtrlSetFont ($Group1,9, 600,-1,"Tahoma")
Dim $WButton4 = GUICtrlCreateButton("Start Selected", 15, 345, 120, 21)
Dim $WButton5 = GUICtrlCreateButton("Stop Selected", 145, 345, 120, 21)
Dim $WButton6 = GUICtrlCreateButton("Delete Selected", 275, 345, 120, 21)
    If Not $DAcount Then
        GUICtrlSetState ($WButton6,$GUI_DISABLE)
    EndIf
Global $WList1 = GUICtrlCreateListView("Index|Server Identity|IP Address|Port|State|Redirect", 5, 40, 400, 245, -1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_SORTASCENDING))
_GUICtrlListViewSetColumnWidth($WList1, 0, 43)
_GUICtrlListViewSetColumnWidth($WList1, 1, 145)
_GUICtrlListViewSetColumnWidth($WList1, 2, 72)
_GUICtrlListViewSetColumnWidth($WList1, 3, 35)
_GUICtrlListViewSetColumnWidth($WList1, 4, 50)
_GUICtrlListViewSetColumnWidth($WList1, 5, 80)
GUISetState(@SW_SHOW)

;If Not $GotServers Then
;           _getServers()
;       EndIf
While 1
    $wmsg = GuiGetMsg()
    Select
    Case $wmsg = $GUI_EVENT_CLOSE Or $wmsg = $WButton3
            GUISetState(@SW_HIDE, $WForm1)
            GUIDelete($WForm1)
            $Edservers = ""
                Return 1
   ;ExitLoop
    Case $wmsg = $WButton1
        If Not $GotServers Then
            _getServers()
        Else
            _RefreshServers()
        EndIf
    
    Case $wmsg = $WButton2
        _RefreshServers()
    Case $wmsg = $WButton4
        Dim $SFields = StringSplit(GUICtrlRead(GUICtrlRead($WList1)), "|")
                $SIndex = $SFields[1]
                    If $SIndex > 0 Then
                        _StartServer($SIndex)
                        _RefreshServers()
                    EndIf
    Case $wmsg = $WButton5
        Dim $SFields = StringSplit(GUICtrlRead(GUICtrlRead($WList1)), "|")
                $SIndex = $SFields[1]
                    If $SIndex > 0 Then
                        _StopServer($SIndex)
                        _RefreshServers()
                    EndIf
    Case $wmsg = $WButton6
        If $GotServers Then
            
            Dim $SFields = StringSplit(GUICtrlRead(GUICtrlRead($WList1)), "|")
                $SIndex = $SFields[1]
                    If $SIndex > 0 Then
                        $Stitle = $SFields[2]
                        $Svip = $SFields[3]
                        
            If $DAcount > 0 Then            
                For $i = 1 To $DAcount
                    If StringInStr($DA[$i], $Stitle) Then
                        $Deny_Delete = 1
                        MsgBox(4112, "Error!", "You May Not Delete the "& $Stitle & " Web Site!")
                        ExitLoop
                    EndIf
                Next
    If Not $Deny_Delete Then
        $Mval = MsgBox(4116, "Confirm Action!", "You have selected to delete the following WWW server:" & @crlf &  "Index: " & $SFields[1] & "," & " Server Title: " & $Stitle & ", IP Address: " & $Svip & @CRLF & "Sellect YES to delete this server, or NO to return to the form and make changes")
    
        If $Mval = 6 Then
            
            _DeleteServer($SIndex, $Stitle)
            _RefreshServers()
        
        ElseIf $Mval = 7 Then
            ContinueLoop
        EndIf           
                
    EndIf
    EndIf           
        Endif
    EndIf
    
    Case Else
   ;;;;;;;
    EndSelect
WEnd
Exit
EndFunc
Func _getServers()
    
Local $WSstate = _ArrayCreate(5,"Starting", "Started", "Stopping", "Stopped")
$w3svc = ObjGet("IIS://" & @ComputerName & "/w3svc")
        If @error <> 0 Then
            MsgBox(4112, "Error!", "Unable to open: "&"IIS://" & @ComputerName & "/w3svc")
            Return 0
        EndIf

Dim $InstID, $InstName, $InstState, $re_dir, $r_dir
    For $WebServer in $w3svc
        $r_dir = ""
        If $WebServer.Class = "IIsWebServer" Then
            $InstID =  $WebServer.Name
            $InstName = $WebServer.ServerComment
            $InstState = $WebServer.ServerState
            $Bindings = $WebServer.ServerBindings
            
                
                    Dim $Sip = StringSplit($Bindings[0], ":")
                    If Not $Sip[1] Then
                        $dspIP = "Default"
                    Else
                        $dspIP = $Sip[1]
                    EndIf
                    $IIsWebVirtualDirObj = ObjGet("IIS://localhost/W3SVC/" & $InstID & "/Root")
                    $redir = $IIsWebVirtualDirObj.HttpRedirect
                    if $redir Then
                    $re_dir = StringSplit ($redir, ",")
                    $r_dir = $re_dir[1]
                    EndIf
               ;next
           ;If $InstID Then;<> $LastIndex Then  
    GUICtrlCreateListViewItem($InstID & "|" & $InstName & "|" & $dspIP & "|" &  $Sip[2]  & "|" &  $WSstate[$InstState] & "|" &  $r_dir,$WList1)
           ;EndIf
               ;$LastIndex = $WebServer.name
               ;next
                    EndIf
                next
                
$GotServers = 1
EndFunc     
Func _RefreshServers()
    _GUICtrlListViewDeleteAllItems($WList1)
    _getServers()
EndFunc
Func _StartServer($Sindx)
    If $Sindx Then
    $Web_Server = ObjGet("IIS://" & @ComputerName & "/w3svc/" & $Sindx)
            $Web_Server.Start()
            If @error <> 0 Then
                MsgBox(4112, "Error!", "Unable to start web server index: " & $Sindx & "!")
                
            Else
                MsgBox(4160, "Information", "Web server index " & $Sindx & " started succesfully!")
            EndIf
        EndIf
EndFunc
Func _StopServer($Sindx)
    If $Sindx Then
    $Web_Server = ObjGet("IIS://" & @ComputerName & "/w3svc/" & $Sindx)
            $Web_Server.Stop()
            If @error <> 0 Then
                MsgBox(4112, "Error!", "Unable to stop web server index: " & $Sindx & "!")
                
            Else
                MsgBox(4160, "Information", "Web server index " & $Sindx & " stopped succesfully!")
            EndIf
        EndIf
EndFunc
Func _DeleteServer($Sindx, $InstName)
    
$Web_Server = ObjGet("IIS://" & @ComputerName & "/w3svc")   

    If $Sindx Then
        $rnRet = $Web_Server.Delete("IIsWebServer", $Sindx)
        
    If Not $rnRet Then
        MsgBox(4160, "Information", "Web server " & $InstName & " at index: " & $Sindx & " deleted succesfully!")
    EndIf
        
    Else    
        MsgBox(4112, "Error!", "Unable to delete web server. Missing server index!")
        
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

pleaz...someone can help me?

Share this post


Link to post
Share on other sites

try start run -->

IIS://REMOTE_OR_LOCAL_PCNAME/w3svc

(it connects to your WWW Service) if this doesn't work, the script can't perform this action either..


Share this post


Link to post
Share on other sites

okay ....

so i don't understand...

i can read other properties from WMI on the same server calling "$oIIS = ObjGet("winmgmts://" & "Amenophis" & "/root/MicrosoftIISv2")"

but not with "$w3svc = ObjGet("IIS://" & $Host & "/w3svc")"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0