groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paco Zarate <conta...@nazcasistemas.com>
Subject Re: Using jacob on Windows to get BIOS info (like server serial number)
Date Fri, 22 May 2015 17:48:34 GMT
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!

Thanks!
Paco.

On Fri, May 15, 2015 at 5:44 AM, Merlin Beedell <MBeedell@cryoserver.com>
wrote:

>  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 set.
>
> 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 (
> https://msdn.microsoft.com/en-us/library/dn792258(v=vs.85).aspx )
>
>        // 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
> https://msdn.microsoft.com/en-us/library/aa394077(v=vs.85).aspx for all
> fields
>
>       }
>
> }
>
>
>

Mime
View raw message