groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Merlin Beedell <>
Subject RE: Using jacob on Windows to get BIOS info (like server serial number)
Date Tue, 11 Aug 2015 09:32:12 GMT
If only I knew how to contribute to a blog of some sort.  Where should I start without having
to learn too much, and where the feedback comments are monitored to remove the irrelevant
responses?  E.g. register, login, type, publish, done!  Preferably a site that is focussed
on Groovy related entries.

Merlin Beedell
From: Paco Zarate []
Sent: 22 May 2015 6:49 PM
To: users <>
Subject: Re: Using jacob on Windows to get BIOS info (like server serial number)

Hey Merlin,
Thanks for sharing this code! It will be helpful for a monitoring script i need for doing
some sysadmin tasks!
It would be great if you publish it on a blog!

On Fri, May 15, 2015 at 5:44 AM, Merlin Beedell <<>>
Just thought one or two of you may be interested on how to get some BIOS and O/S level details
on a Windows platform.  To do this you will need to use the JACOB interface to COM, that allows
Java to interact with com/dcom components.  In this case, to access the WMI Scripting feature
Note: JACOB is installed with Groovy when using the Windows distribution (not the zip or scripted
installer versions). This is cribbed from the excellent example already in the Groovy distribution.

Now to figure how to do similar for Linux (dmidecode + ?) and on VM platforms!
Why? To find some sort of meaningful but ‘unique’ attribute(s) of the server on which
the service is running.

Merlin Beedell

import org.codehaus.groovy.scriptom.*;
import static org.codehaus.groovy.scriptom.tlb.wbemscripting.WbemFlagEnum.*;
import static org.codehaus.groovy.scriptom.util.wbemscripting.WbemDateTime.*

    org.codehaus.groovy.scriptom.Scriptom.inApartment {
        def locator = new org.codehaus.groovy.scriptom.ActiveXObject('WbemScripting.SWbemLocator')
        def services = locator.ConnectServer('.')
        def returnState
        def Kb2Mb = 1024
        def nf = java.text.NumberFormat.getIntegerInstance()
      def proc_query
       // Lets get some Windows O/S details (
       // you can specify which details to return, the * for all details..
      proc_query = "SELECT Caption, Version, CSDVersion, OSArchitecture, FreePhysicalMemory,
TotalVisibleMemorySize FROM Win32_OperatingSystem"
      //proc_query = "SELECT * FROM Win32_OperatingSystem"
      for (process in services.ExecQuery(proc_query, 'WQL', wbemFlagForwardOnly) )
        def mem_free = process.FreePhysicalMemory as Integer
        def mem_Total = process.TotalVisibleMemorySize as Integer
        //def mem_swap = (process.TotalSwapSpaceSize+""?:"0") as Integer
        println ("Free Mem = ${nf.format(mem_free / Kb2Mb)}Mb   Total Mem = ${nf.format(mem_Total/Kb2Mb)}Mb
        println "O/S = $process.Caption [Ver $process.Version] $process.CSDVersion [$process.OSArchitecture]\n\n"
        //println "Locale = $process.Locale"
      //  Now to get some BIOS info
      proc_query = "SELECT * FROM Win32_BIOS"
      for (process in services.ExecQuery(proc_query, 'WQL', wbemFlagForwardOnly) )
        println process.SerialNumber
        //println process.dump()
        println process.CurrentLanguage
        println process.Description
        println toJavaDate(process.ReleaseDate)
        println process.Manufacturer
      //see for all fields

View raw message