WMI objects through DTS

  • Is it possible to access winmgmts objects (Windows Management Interface) through DTS ActiveX tasks - or anything else?

    If so, how?

    I'm at a loss. Thanks.

  • Beags,

    I know pretty close to zilch about this subject, but is the following link any use?

    http://groups.google.com/groups?q=wmi+dts+activex&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=065f01c2ccc5%2445a3edf0%24d2f82ecf%40TK2MSFTNGXA09&rnum=3

    In case the URL don't paste nicely, the thrust of the thread is:

    quote:


    I have a DTS package that gets the name of the SQL server

    running the packge. Part of the ActiveX script goes like

    this:

    strServer = "."

    set objLocator = CreateObjec

    ("WbemScripting.SWbemLocator")

    Set objServices = objLocator.ConnectServer

    (strServer, "root\MicrosoftSQLServer")

    objServices.Security_.ImpersonationLevel = 3

    Set colInstances = objServices.InstancesOf

    ("MSSQL_SQLServer")

    i = 0

    For Each objInstance In colInstances

    i = i + 1

    DTSGlobalVariables("Servername").Value = objInstance.Name

    msgbox objInstance.Truename & " as instance Truename

    from WMI"

    Next

    If I run this script on a SQL 2000 SP2 server,

    objInstance.Name returns the name of the SQL server

    instance. On a SQL 2000 SP3 server, objInstance.Name

    returns "(local)" (no quotes). To get the instance name,

    I now need to request the TrueName property. Has anyone

    else noticed this? Any explanation? I'm no WMI expert,

    and maybe I should be using Truename anyway, but this

    seems like a strange side effect. Any information would

    be appreciated.


    How's the weather there in London. 100 degrees today eh?

    Cheers,

    - Mark


    Cheers,
    - Mark

  • Hey Mark, thanks for that. Looks like it may just do it, will try it out tomorrow and see how it goes.

    Took the London hint and updated my info.

    Later,

    Nick

  • While c/p + modify of that didn't solve my problem, it did get me to the

    correct section of .Net documentation 🙂 and with that + your link I

    finally got it working.

     '**********************************************************************
    
    ' Visual Basic ActiveX Script
    '***********************************************************************
    *

    Function Main()
    strServer = "SomeMachineSomewhere"
    Const HARD_DISK = 3

    set objLocator = CreateObject("WbemScripting.SWbemLocator")
    Set objServices = objLocator.ConnectServer(strServer, "root\cimv2")

    objServices.Security_.ImpersonationLevel = 3

    Set colInstances = objServices.ExecQuery("SELECT * FROM
    Win32_LogicalDisk WHERE DriveType = " & HARD_DISK & "")

    For Each Drive In colInstances
    If Not IsNull(Drive.Size) Then
    MsgBox ("Drive " & Drive.deviceid & " Total Size: " &
    round(Drive.Size/1024/1024/1024,1) & " Free Space: " &
    round(Drive.FreeSpace/1024/1024/1024,1) )
    Else
    MsgBox ("Drive " & Drive.deviceid & " is not available.")
    End If
    Next
    Main = DTSTaskExecResult_Success
    End Function

    This returns disk size and free space on a remote server - and seems to report correctly on clusters.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply