Re: Help will empty field entry handling



On May 19, 11:28 am, "Todd Vargo" <tlva...@xxxxxxxxxxxxxx> 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
.



Relevant Pages

  • Re: Help with incremented object numbers
    ... Dim ObjWMI, Ts, objItem, colItems, SysName, Lst, intNumber ...   Sub GetDisc ... DiscriptionArea.InnerHTML = strDISC ...
    (microsoft.public.scripting.vbscript)
  • Re: Help will empty field entry handling
    ... however some 3rd party oem machines have an empty serial ... Set colItems = objWMIService.ExecQuery("SELECT * FROM ... For Each objItem in colItems ... Wscript.Echo "SerialNumber: no serial number found" ...
    (microsoft.public.scripting.vbscript)
  • Hardware Info Script
    ... Now I slapped together this script which is kinda messy. ... For Each objItem in colItems ... intRow = intRow + 1 ...
    (microsoft.public.scripting.vbscript)
  • Re: Network Script Help
    ... For Each objItem in colItems ... objItem.Manufacturer & VBCRLF ... Set colItems = objWMIService.ExecQuery("Select * from ...
    (microsoft.public.windows.server.scripting)
  • Re: Still having great difficulty with error handling
    ... machne that is "down" I get the error below - any insight as to that? ... >> For Each objItem In colItems ... > Microsoft MVP Scripting ...
    (microsoft.public.scripting.vbscript)