Windows Vista Forums

Help will empty field entry handling

  1. #1


    Daz Guest

    Help will empty field entry handling

    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

    You help would be greatly appreciated.

    Cheers,
    Daz

      My System SpecsSystem Spec

  2. #2


    Todd Vargo Guest

    Re: Help will empty field entry handling

    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)


      My System SpecsSystem Spec

  3. #3


    Daz Guest

    Re: Help will empty field entry handling

    On May 19, 11:28*am, "Todd Vargo" <tlva...@xxxxxx> wrote:

    > 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)
    Todd,

    Thank you very much for your help - thats perfect! does exactly what i
    wanted.

    Cheers,
    Daz

      My System SpecsSystem Spec

Help will empty field entry handling

Similar Threads
Thread Thread Starter Forum Replies Last Post
(Empty) 'New' menu, empty start menu, BRAND NEW VISTA! kikiluna General Discussion 6 27 Dec 2008
Vista explorer - Folder empty, but is not empty, why? Sandra Baum Vista General 0 14 Dec 2008
Handling DBX Files Oldgeoff .NET General 0 21 Apr 2008
file folder icons display non-empty folders as empty nodaway Vista file management 1 26 Dec 2007
Error Handling Jacob PowerShell 8 02 Oct 2007