02 December 2010

Host Info - Windows Server pt. 1

What's this, a Windows Server post?  He's lost his mind, right?!
This post can be chalked up to "what if X", as in, what if I want to
get host information on a Windows server from the command line.  So,
adding to the host info series, here's how to get memory, cpu, and boot
information in Windows 2003.  Our host details are:
        HOST:           fenster
        PROMPT:         fenster [C:\]
        OS:             Windows 2003 Server
Of note, the commands that follow may be usable on other versions
of Windows Server, though only 2003 was tested against.  Moving on,
getting the system's memory information is actually quite trivial via
'systeminfo':
        fenster [C:\] systeminfo | findstr /C:"Total Physical Memory" /C:"File: Max" 
        Total Physical Memory:     1,023 MB
        Page File: Max Size:       2,473 MB
Well that was nice, both values from one command.  How about our CPU
information?  There's actually three ways that I know of, the first is
via 'set':
        fenster [C:\] set processor
        PROCESSOR_ARCHITECTURE=x86
        PROCESSOR_IDENTIFIER=x86 Family 15 Model 47 Stepping 0, AuthenticAMD
        PROCESSOR_LEVEL=15
        PROCESSOR_REVISION=2f00
The above outputs preset environment variables.  The
'PROCESSOR_ARCHITECTURE' value of 'x86' tells us this is a 32 bit
installation (see note).  We can also see that this is an AMD chipset,
though not much else without having to look up or remember the chipset.
One issue with this method, since these are environment variables,
is they can be overwritten on the fly:
        fenster [C:\] set processor_architecture
        PROCESSOR_ARCHITECTURE=x86
        fenster [C:\] set processor_architecture=x64
        fenster [C:\] set processor_architecture
        PROCESSOR_ARCHITECTURE=x64
Another means of getting the CPU info is via 'reg'.  Effectively the same
information is presented as before, but that is because the environment
variables from earlier are set based on the data in the Windows registry
which we'll query now:
        fenster [C:\] reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PROCESSOR*

        HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
            PROCESSOR_ARCHITECTURE    REG_SZ    x86
            PROCESSOR_IDENTIFIER    REG_SZ    x86 Family 15 Model 47 Stepping 0, AuthenticAMD
            PROCESSOR_LEVEL    REG_SZ    15
            PROCESSOR_REVISION    REG_SZ    2f00
This give up the same output seen earlier.  To get details on a particular
CPU, identify it numerically in another 'reg' query:
        fenster [C:\] reg query HKLM\Hardware\Description\System\CentralProcessor\0 | findstr /C:"ProcessorName" /C:"~MHz"
            ProcessorNameString    REG_SZ    AMD Athlon(tm) 64 Processor 3500+
            ~MHz    REG_DWORD    0x88c
We can now see the specific model of the processor and its speed.
The '~MHz' value is in hex.  So '0x88c' translates to 2188 in decimal,
as in 2188 MHz.  The final place to get the data on the CPU is from
'systeminfo':
        fenster [C:\] systeminfo
        <snip...>
        Processor(s):              1 Processor(s) Installed.
                                   [01]: x86 Family 15 Model 47 Stepping 0 AuthenticAMD ~2188 Mhz
        <snip...>
Here we get a count, make, and speed of the CPU.  Like the environment
variables above, 'systeminfo' also retrieves its information from
the Windows registry.  To close out this post, boot information.
Unfortunately, Windows doesn't have much to give up here.  Once again,
back to 'systeminfo':
        fenster [C:\] systeminfo | findstr /C:"Boot Device" /C:"Windows Dir"
        Windows Directory:         C:\WINDOWS
        Boot Device:               \Device\HarddiskVolume1
Windows provides us with the 'windows' directory and the boot device used.


Note:  The value of PROCESSOR_ARCHITECTURE can actually be any of 'x86',
        'IA64', or 'AMD64'.  These break down to x86 = 32 bit,
        IA64 = 32 bit with 64 bit emulation, and AMD64 = 64 bit or
        32 bit with 64 bit emulation.  If 'PROCESSOR_ARCHITEW6432' or
        'ProgramW6432' exist as an environment variable and registry key,
        the chipset is 32 bit with 64 bit emulation.  Additionally, if
        'PROCESSOR_IDENTIFIER' contains the string 'x86', the chipset
        is 32 bit.  If instead it contains either 'AMD64' or 'EM64T',
        it is 64 bit.  In either 64 bit case of 'PROCESSOR_IDENTIFIER',
        'PROCESSOR_ARCHITECTURE' will report 'AMD64'.