Saturday, October 3, 2009

VBScript - Get Remote Asset Tag (Serial Number)

Function AssetNumber(strComputer)
    Dim objWmi, objWmiCS, obj, retval
    On Error Resume Next
    Set objWmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
        strComputer & "\root\cimv2")
    If err.Number <> 0 Then
        wscript.echo "error: " & err.Number & " / " & err.Description
        err.Clear
        Set objWMI = Nothing
        retval = "*** unavailable ***"
    Else
        Set objWmiCS = objWmi.ExecQuery("select * from Win32_ComputerSystemProduct")
        For Each obj in objWmiCS
            retval = obj.IdentifyingNumber
        Next
        Set objWmiCS = Nothing
        Set objWMI = Nothing
    End If
    AssetNumber = retval
End Function

wscript.echo AssetNumber("holland")

No comments:

Post a Comment