Daz wrote:
> Hi all,
>
> am using the following code to pull the motherboard serial number from
> machines, however some 3rd party oem machines have an empty serial
> number field and i would like to have the code report "no serial
> number found" if the field is empty of null...
>
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
> \CIMV2")
> Set colItems = objWMIService.ExecQuery( "SELECT * FROM
> Win32_BaseBoard",,48)
> For Each objItem in colItems
> If IsNull(objItem.SerialNumber) Then
> MsgBox(objItem.SerialNumber)
> End If
> Next
>
> and
>
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
> \CIMV2")
> Set colItems = objWMIService.ExecQuery( _
> "SELECT * FROM Win32_BaseBoard",,48)
> For Each objItem in colItems
> Wscript.Echo "-----------------------------------"
> Wscript.Echo "Win32_BaseBoard instance"
> Wscript.Echo "-----------------------------------"
> Wscript.Echo "SerialNumber: " & objItem.SerialNumber
> Next One way is to store the value in a variable.
sn = objItem.SerialNumber
If Trim(sn) = "" Then
sn = "no serial number found"
End If
Another way is to use an IF condition where needed.
For Each objItem in colItems
Wscript.Echo "-----------------------------------"
Wscript.Echo "Win32_BaseBoard instance"
Wscript.Echo "-----------------------------------"
If Trim(objItem.SerialNumber) = "" Then
Wscript.Echo "SerialNumber: no serial number found"
Else
Wscript.Echo "SerialNumber: " & objItem.SerialNumber
End If
Next
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)