« Previous Next »

Thread: Problem while trying to execute ADSI Script on Remote machine

Last post 04-14-2009 2:59 AM by chattygk. 2 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (3 items)

Sort Posts:

  • 04-13-2009, 9:17 AM

    • chattygk
    • Not Ranked
    • Joined on 04-13-2009, 9:09 AM
    • Posts 2

    Problem while trying to execute ADSI Script on Remote machine

    Hi All,

    I am new to IIS and configuring IIS using ADSI. I am trying to execute following script (which I found somewhere on the Internet) on remote machine and I get error 800A0046 , "Permission Denied 'GetObject'". When I copy the script on that remote machine and execute it locally, I get the desired output.

     OPTION EXPLICIT

    DIM CRLF, TAB
    DIM strServer
    DIM objWebService

    TAB  = CHR( 9 )
    CRLF = CHR( 13 ) & CHR( 10 )

    IF WScript.Arguments.Length = 1 THEN
       strServer = WScript.Arguments( 0 )
    ELSE
        strServer = "localhost"
    END IF


    WScript.Echo "Enumerating websites on " & strServer & CRLF
    SET objWebService = GetObject( "IIS://" & strServer & "/W3SVC" )
    EnumWebsites objWebService


    SUB EnumWebsites( objWebService )
        DIM objWebServer, strBindings

        FOR EACH objWebServer IN objWebService
            IF objWebserver.Class = "IIsWebServer" THEN
                WScript.Echo _
                    "Site ID = " & objWebserver.Name & CRLF & _
                    "Comment = """ & objWebServer.ServerComment & """ " & CRLF & _
                    "State   = " & State2Desc( objWebserver.ServerState ) & CRLF & _
                    "LogDir  = " & objWebServer.LogFileDirectory & _
                    ""

                ' Enumerate the HTTP bindings (ServerBindings) and
                ' SSL bindings (SecureBindings)
                strBindings = EnumBindings( objWebServer.ServerBindings ) & _
                              EnumBindings( objWebServer.SecureBindings )
                IF NOT strBindings = "" THEN
                    WScript.Echo "IP Address" & TAB & _
                                 "Port" & TAB & _
                                 "Host" & CRLF & _
                                 strBindings
                END IF
            END IF
        NEXT

    END SUB

    FUNCTION EnumBindings( objBindingList )
        DIM i, strIP, strPort, strHost
        DIM reBinding, reMatch, reMatches
        SET reBinding = NEW RegExp
        reBinding.Pattern = "([^:]*):([^:]*):(.*)"

        FOR i = LBOUND( objBindingList ) TO UBOUND( objBindingList )
            ' objBindingList( i ) is a string looking like IP:Port:Host
            SET reMatches = reBinding.Execute( objBindingList( i ) )
            FOR EACH reMatch IN reMatches
                strIP = reMatch.SubMatches( 0 )
                strPort = reMatch.SubMatches( 1 )
                strHost = reMatch.SubMatches( 2 )

                ' Do some pretty processing
                IF strIP = "" THEN strIP = "All Unassigned"
                IF strHost = "" THEN strHost = "*"
                IF LEN( strIP ) < 8 THEN strIP = strIP & TAB

                EnumBindings = EnumBindings & _
                               strIP & TAB & _
                               strPort & TAB & _
                               strHost & TAB & _
                               ""
            NEXT

            EnumBindings = EnumBindings & CRLF
        NEXT

    END FUNCTION

    FUNCTION State2Desc( nState )
        SELECT CASE nState
        CASE 1
            State2Desc = "Starting (MD_SERVER_STATE_STARTING)"
        CASE 2
            State2Desc = "Started (MD_SERVER_STATE_STARTED)"
        CASE 3
            State2Desc = "Stopping (MD_SERVER_STATE_STOPPING)"
        CASE 4
            State2Desc = "Stopped (MD_SERVER_STATE_STOPPED)"
        CASE 5
            State2Desc = "Pausing (MD_SERVER_STATE_PAUSING)"
        CASE 6
            State2Desc = "Paused (MD_SERVER_STATE_PAUSED)"
        CASE 7
            State2Desc = "Continuing (MD_SERVER_STATE_CONTINUING)"
        CASE ELSE
            State2Desc = "Unknown state"
        END SELECT

    END FUNCTION

    What should I do to execute it from remote location, like from my desktop to on that server? The remote server is a Windows Server 2003 x64 Enterprise Edition. It seems there needs to be some change for the permissions.

    Please let me know if I should provide some more information. Any help / assistance will be greatly appreciated.

    Regards,

    Chaitanya

  • 04-13-2009, 10:47 AM In reply to

    Re: Problem while trying to execute ADSI Script on Remote machine

    Cant be for sure ... but there could be a possibility that remote execution could be disable through Group Policy (reason being you are able to execute it locally)

    Secondly, you could try impersonation in your script. the script that you have shown seems like it was written for testing purposes...

    Further you can check the IIS scripting repository (http://www.microsoft.com/technet/scriptcenter/scripts/iis/default.mspx) to get more info and sample scripts

    Hope this helps....  

    Regards,
    MA Khan
    http://www.iisworkstation.com

    “Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
  • 04-14-2009, 2:59 AM In reply to

    • chattygk
    • Not Ranked
    • Joined on 04-13-2009, 9:09 AM
    • Posts 2

    Re: Problem while trying to execute ADSI Script on Remote machine

    Thank you for your response. I will try using Impersonation in my script.

    Regards,

    Chaitanya

Page 1 of 1 (3 items)
Microsoft Communities