Jump to content

Wmi Queries Re: Platform / Detection


Recommended Posts

Hi all.

Have customised a system information script that uses WMI do collect data (and added code generated from 'Scriptomatic' - nice one SvenP). I know that AutoIt has some nice macro's that supply some useful system information (mainly by reading registry info). It occurred to me that a script i am writing at the moment is likely to be run on a number of WinNT / 95 / 98 (with IE4) systems - and as such I believe won't have WMI... but maybe i'm getting confused with WSH :think:

  • will the script throw an error, or just return "null" strings etc ? (got no systems earlier than winXP to check)
  • Is there an alternative to WMI for in-depth system info ?
  • any code examples to detect WMI (maybe an idea for a future macro ie @WMI returns true if present etc ?
TIA :( (Searched forum without joy) Edited by plastix
Link to comment
Share on other sites

hi forger. thanks. specifically, i am getting the following info:

CIM_Processor: Name, MaxClockSpeed, Description, SystemName

Win32_OperatingSystem: Caption, BuildNumber, ServicePackMajorVersion, ServicePackMinorVersion, FreePhysicalMemory, FreeVirtualMemory

Win32_ComputerSystem: TotalPhysicalMemory, Domain, Workgroup

Win32_VideoController: Description

Win32_SoundDevice: Description

...and use Scripting.FileSystemObject.Drives for drive info.

Some items are non-essential. What would be useful to know is whether the script would fail or not if WMI is not available. If there are means of obtaining the information without WMI calls, then I could set up a check for Win98/NT etc, and collect the information another way (if i can't check to see if WMI is available).

All help greatfully received. TIA for your time :think:

Link to comment
Share on other sites

Windows management instrumentation requires the wmicore: http://www.microsoft.com/downloads/details...5B-FBF236E0E875

It is pre-installed in Windows Me, Windows 2000, Windows XP and Windows Server 2003:

http://www.microsoft.com/technet/scriptcen...wmifaq.mspx#EJC

Yes, logically the scripts fail if WMI is not present. I believe you can check if wmi is supported with one of the following:

a. the output of "wmic" command in a dos. (edit: I just found out that it's not used in win9x or nt, only remotely this can be used :) )

I think if wmi is not installed the command is not recognized, and you get something like this:

'wmic' is not recognized as an internal or external command,

operable program or batch file.

You can use StdoutRead (read the help file)

b. by simply checking if the windows version is one of the above mentioned (but that doesn't mean they didn't update, so I'd go with the first one)

c. I found out the installation directory of wmicore:

$wmicoredir = @SystemDir & "\wbem"

I also found a helpful link: http://www.wtcs.org/snmp4tpc/wmi.htm#Insta...%20Windows%209x

d. Logically in Windows NT versions (NT,XP,2000,2003) wmi runs as a service, whereas in Windows 95/98 it should show up in a value under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServices key.

Now you should be able to identify through checking if the service or the value under that key exists for each windows version (I hope)

How to get a lot of info through wmi scripting? Windows XP Pro has a nice command: systeminfo

Unfortunately it's not in windows xp home edition or any other windows from what I know (maybe windows 2003 has it).

Someone could help you furthermore with wmi scripting if you don't know how to call the objects you need, because I haven't used it a lot. Some are supported by autoit already as macros and some can be found in the registry, but I've never dug that deep to be honest :think:

For example, (windows xp pro sp2 here) under: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum you may find a lot of devices, you could simply extract the info from there:

$regvalue = RegRead ( "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\PCI\VEN_10DE&DEV_008A&SUBSYS_00801462&REV_A1\3&13c0b0c5&0&30, "DeviceDesc")
;This the PCI for my sound card: "DeviceDesc"="Realtek AC'97 Audio"
MsgBox("","regstring","I have this sound card: " & $regvalue)

Note: A lot of stuff varies under Enum, but it still is a possible workaround instead of wmi. Maybe someone else can suggest different and better registry places here :(

Edited by forger
Link to comment
Share on other sites

Cheers forger. Actually, i have the WMI calls working nicely... I was actually thinking ahead to what would happen on systems without WMI. I guess i could check to see that IE >=5 installed (via registry HKLM\Microsoft\Windows\CurrentVersion\App Path\IEXPLORE.EXE - then FileGetVersion() on "Path" from registry)... that way WMI should be installed also. My thoughts are more ot do with trapping / modifying script running if WMI not present - and maybe providing some of the info via other means...

Thanks again

Link to comment
Share on other sites

I just edited my post, I found some statements that were not true hehe :think:

but the "d." part should cover your question I guess.

Or this would be a quick alternative:

$wmimainfile = @SystemDir & "\wbem\winmgmt.exe"
If FileExists($wmimainfile) Then
    MsgBox("","found","wmi exists")
EndIf
Edited by forger
Link to comment
Share on other sites

I *think* I just found a way to extract a lot of info without using wmi. From what I understand, you can use it with windows 9x as well. Thanks for making me dig this up :think:

For example, go to start > run and type this:

start msinfo32 /categories +ComponentsMultimediaSound+ComponentsDisplay /report c:\report.txt

You can see the categories available from which you can choose to +(add) or -(remove) by:

start msinfo32 /showcategories

Here's my output:

System Information report written at: 04/09/06 03:07:05

System Name: CHOKE-W319TMPW6

[system Summary]Item Value

OS Name Microsoft Windows XP Professional

Version 5.1.2600 Service Pack 2 Build 2600

OS Manufacturer Microsoft Corporation

System Name CHOKE-W319TMPW6

System Manufacturer NVIDIA

System Model AWRDACPI

System Type X86-based PC

Processor x86 Family 6 Model 8 Stepping 1 AuthenticAMD ~1749 Mhz

BIOS Version/Date Phoenix Technologies, LTD 6.00 PG, 20.1.2005

SMBIOS Version 2.2

Windows Directory C:\WINDOWS

System Directory C:\WINDOWS\system32

Boot Device \Device\HarddiskVolume1

Locale Greece

Hardware Abstraction Layer Version = "5.1.2600.2180 (xpsp_sp2_rtm.040803-2158)"

User Name CHOKE-W319TMPW6\Radevic

Time Zone Central Europe Standard Time

Total Physical Memory 512,00 MB

Available Physical Memory 184,73 MB

Total Virtual Memory 2,00 GB

Available Virtual Memory 1,96 GB

Page File Space 1,97 GB

Page File C:\pagefile.sys

[Components]

[sound Device]

Item Value

Name Realtek AC'97 Audio

Manufacturer Realtek

Status OK

PNP Device ID PCI\VEN_10DE&DEV_008A&SUBSYS_00801462&REV_A1\3&13C0B0C5&0&30

I/O Port 0x0000E000-0x0000E0FF

I/O Port 0x0000E400-0x0000E47F

Memory Address 0xE4004000-0xE4004FFF

IRQ Channel IRQ 20

Driver c:\windows\system32\drivers\alcxwdm.sys (5.10.5900 built by: WinDDK, 3,48 MB (3.644.800 bytes), 27.3.2006 2:53)

[Display]

Item Value

Name NVIDIA GeForce FX 5500

PNP Device ID PCI\VEN_10DE&DEV_0326&SUBSYS_93661462&REV_A1\4&102AC5BC&0&00F0

Adapter Type GeForce FX 5500, NVIDIA compatible

Adapter Description NVIDIA GeForce FX 5500

Adapter RAM 128,00 MB (134.217.728 bytes)

Installed Drivers nv4_disp.dll

Driver Version 6.14.10.8421

INF File oem7.inf (nv4_NV3x section)

Color Planes 1

Color Table Entries 4294967296

Resolution 1024 x 768 x 85 hertz

Bits/Pixel 32

Memory Address 0xE2000000-0xE3FFFFFF

Memory Address 0xD0000000-0xD7FFFFFF

IRQ Channel IRQ 16

I/O Port 0x000003B0-0x000003BB

I/O Port 0x000003C0-0x000003DF

Memory Address 0xA0000-0xBFFFF

Driver c:\windows\system32\drivers\nv4_mini.sys (6.14.10.8421, 3,48 MB (3.650.368 bytes), 27.3.2006 2:12)

Cheers! :(

Edit: Can someone test this command on windows 9x please?

Edited by forger
Link to comment
Share on other sites

madness :think:

Nice work forger.

MsInfo32 should work on all platforms i guess... limiting to a few switches should speed it up and miss out the drivers etc etc... the only pain is the output is a little tricky to parse... maybe can get all the info out "easily"... will experiment.

WMI is quicker +, so I think (if i can parse this output) i'll use that if it is available - otherwise i'll fiddle with this. Nice one again. Looks very promising.

OK. Here's a "dirty" and kinda neat trick with this baby. Output is (on my system) in Unicode. The text uses TAB delimiter... so an idea is to convert the text to ANSI, then read it in Line by Line and replace first TAB in each with "=". If you look closely, that will convert the file into something that looks like a standard INI file :( - and then, nicely, you can use IniRead to get the info out ;)

$uniFile = "report.txt"
$ansiFile = "report_ansi.txt"
RunWait(@ComSpec & ' /c Type "' & $uniFile & '" > "' & $ansiFile & '"',"",@SW_HIDE)
MsgBox(0,"Converted To ANSI",":)")

$filehandle = FileOpen("report_ansi.txt",0)
$output = FileOpen("report.ini",2)
While 1
    $line = FileReadLine($filehandle)
    If @error = -1 Then ExitLoop
$parsed = StringReplace($line,Chr(9),"=",1)
FileWriteLine($output,$parsed)
Wend
FileClose($filehandle)
FileClose($output)

$pc = IniRead("report.ini","System Summary","Processor","Unknown")
msgbox(0,"Info",$pc)

Could do with some refining, but its a start :)

Edited by plastix
Link to comment
Share on other sites

WMI is quicker

Well, you can always do:

start /wait msinfo32 ...

That will wait for the msinfo to end. It takes a couple of seconds on my machine and RunWait with start /wait would work perfectly pausing the script! :(

About the msinfo switches: http://support.microsoft.com/default.aspx?...kb;en-us;300887

$uniFile = "report.txt"
$ansiFile = "report_ansi.txt"
RunWait(@ComSpec & ' /c Type "' & $uniFile & '" > "' & $ansiFile & '"',"",@SW_HIDE)
MsgBox(0,"Converted To ANSI",":)")

$filehandle = FileOpen("report_ansi.txt",0)
$output = FileOpen("report.ini",2)
While 1
    $line = FileReadLine($filehandle)
    If @error = -1 Then ExitLoop
$parsed = StringReplace($line,Chr(9),"=",1)
FileWriteLine($output,$parsed)
Wend
FileClose($filehandle)
FileClose($output)

$pc = IniRead("report.ini","System Summary","Processor","Unknown")
msgbox(0,"Info",$pc)

Could do with some refining, but its a start :think:

How about this:

#include <File.au3>

Func _GetInfoFromMSInfo32($_Outputfile = "_report.ini", $_Categories = "+all")
    If $_Outputfile = "" Then
        $_Outputfile = "_report.ini"
    EndIf
    Local $_Outputfiletmp = StringTrimRight($_Outputfile, 4) & '_tmp.ini', $_Readline, $_check
    FileDelete($_Outputfile)
    FileDelete($_Outputfiletmp)
    RunWait(@ComSpec & " /c start /wait msinfo32 /categories " & $_Categories & " /report " & $_Outputfile, "", @SW_HIDE)
    If @OSTYPE = "WIN32_NT" Then
        RunWait(@ComSpec & ' /c Type "' & $_Outputfile & '" >> "' & $_Outputfiletmp & '"', "", @SW_HIDE)
        FileMove($_Outputfiletmp, $_Outputfile, 1)
    EndIf
    _ReplaceStringInFile ($_Outputfile, @TAB, "=")
    _ReplaceStringInFile ($_Outputfile, "Item=Value=", "")
    $i = 1
    While $i <= _FileCountLines($_Outputfile)
        $_Readline = FileReadLine($_Outputfile, $i)
        If StringLeft($_Readline, 37) = "System Information report written at:" Then
            _FileWriteToLine ($_Outputfile, $i, "[Report]" & @CRLF & "Report Time=" & StringTrimLeft($_Readline, 38), 1)
            $i = $i - 2;Resets the line number
        ElseIf StringLeft($_Readline, 12) = "System Name:" Then
            _FileWriteToLine ($_Outputfile, $i, "", 1);Deletes the line
            $i = $i - 1;Resets the line number
        ElseIf StringRight($_Readline, 1) = "=" Then
            _FileWriteToLine ($_Outputfile, $i, StringTrimRight($_Readline, 1), 1)
            $i = $i - 1
        ElseIf $_Readline = "" Then
            _FileWriteToLine ($_Outputfile, $i, "", 1);Deletes the line
        EndIf
        $i = $i + 1
    WEnd
    Return $_Outputfile
EndFunc

$Outputfile = _GetInfoFromMSInfo32("","+ComponentsMultimediaSound+ComponentsDisplay")
Run("notepad " & $Outputfile)

Result:

[Report]
Report Time=04/09/06 16:33:28
[System Summary]

OS Name=Microsoft Windows XP Professional
Version=5.1.2600 Service Pack 2 Build 2600
OS Manufacturer=Microsoft Corporation
System Name=CHOKE-W319TMPW6
System Manufacturer=NVIDIA
System Model=AWRDACPI
System Type=X86-based PC
Processor=x86 Family 6 Model 8 Stepping 1 AuthenticAMD ~1749 Mhz
BIOS Version/Date=Phoenix Technologies, LTD 6.00 PG, 20.1.2005
SMBIOS Version=2.2
Windows Directory=C:\WINDOWS
System Directory=C:\WINDOWS\system32
Boot Device=\Device\HarddiskVolume1
Locale=Greece
Hardware Abstraction Layer=Version = "5.1.2600.2180 (xpsp_sp2_rtm.040803-2158)"
User Name=CHOKE-W319TMPW6\Radevic
Time Zone=Central Europe Standard Time
Total Physical Memory=512,00 MB
Available Physical Memory=182,55 MB
Total Virtual Memory=2,00 GB
Available Virtual Memory=1,96 GB
Page File Space=1,97 GB
Page File=C:\pagefile.sys
[Components]

[Sound Device]

Name=Realtek AC'97 Audio
Manufacturer=Realtek
Status=OK
PNP Device ID=PCI\VEN_10DE&DEV_008A&SUBSYS_00801462&REV_A1\3&13C0B0C5&0&30
I/O Port=0x0000E000-0x0000E0FF
I/O Port=0x0000E400-0x0000E47F
Memory Address=0xE4004000-0xE4004FFF
IRQ Channel=IRQ 20
Driver=c:\windows\system32\drivers\alcxwdm.sys (5.10.5900 built by: WinDDK, 3,48 MB (3.644.800 bytes), 27.3.2006 2:53)
[Display]

Name=NVIDIA GeForce FX 5500
PNP Device ID=PCI\VEN_10DE&DEV_0326&SUBSYS_93661462&REV_A1\4&102AC5BC&0&00F0
Adapter Type=GeForce FX 5500, NVIDIA compatible
Adapter Description=NVIDIA GeForce FX 5500
Adapter RAM=128,00 MB (134.217.728 bytes)
Installed Drivers=nv4_disp.dll
Driver Version=6.14.10.8421
INF File=oem7.inf (nv4_NV3x section)
Color Planes=1
Color Table Entries=4294967296
Resolution=1024 x 768 x 85 hertz
Bits/Pixel=32
Memory Address=0xE2000000-0xE3FFFFFF
Memory Address=0xD0000000-0xD7FFFFFF
IRQ Channel=IRQ 16
I/O Port=0x000003B0-0x000003BB
I/O Port=0x000003C0-0x000003DF
Memory Address=0xA0000-0xBFFFF
Driver=c:\windows\system32\drivers\nv4_mini.sys (6.14.10.8421, 3,48 MB (3.650.368 bytes), 27.3.2006 2:12)

or maybe:

$Outputfile = _GetInfoFromMSInfo32("","+ComponentsMultimediaSound+ComponentsDisplay")
MsgBox("","title",IniRead($Outputfile, "System Summary", "Processor", "Unknown"))

Result: A message box with "x86 Family 6 Model 8 Stepping 1 AuthenticAMD ~1749 Mhz" :)

But the problem is which categories are available in windows 9x/me

Edited by forger
Link to comment
Share on other sites

Um, Sadly I think you will find that not all those switches are present for older versions of MSINFO/MSINFO32. :think:

A lot of the info is already available from existing AutoIT functions and you should be able to get most of the rest directly from the registry.

The forums have a lot of ideas as these are not unique requests.

Link to comment
Share on other sites

Not all, but they ought to have the same structure.

I'm looking to see the differences, I hope I'll be able to.

By the way, I've already mentioned the registry and AutoIt support for most of these stuff at this post

Edit: and it's not bad to have an alternative :think:

Edited by forger
Link to comment
Share on other sites

OK. fiddled on a few platforms over this weekend.

vanilla Win95OSR2 - no dice (No msinfo/msinfo32)

vanilla Win98SE - msinfo32 present. command line call opened msinfo32 on-screen, but the report switch didn't spool output to file. may have a different syntax, but likely not supported

vanilla WinNT4 - pending...

...all in all, not that favourable.

Link to comment
Share on other sites

Edit: MSINFO32 for windows 95 comes bundled with few multimedia products. They'd have to get it, I guess bill gates didn't think that far back at that time :think:

Edit 2: Can you export a .nfo or .txt and upload & attach it here from windows 98? I'd like to see the differences for msinfo32 between xp and 98

Oh well, worth a shot :(

You might consider checking if WINMSD command is available:

WINMSD

Microsoft Windows diagnostics
Reports: Memory use, Services, Devices, IRQ's Ports, Environment variables,
Network (rights, transport, stats), Hardware including Display adapter.

Syntax
      WINMSD [\\computername] options

Options:
       /a          All details
       /s          Summary details only
       /f          Send output to a file <computername.txt> in the current directory 
       /p          Send output to a printer

      WINMSD with no switches will open the GUI with details of the computer you are logged into. 

When a remote computername is specified then less info will be reported
e.g. Diskspace and Memory won't be listed

Hot keys within the GUI:

SHIFT - F2 copies the current tab to the clipboard,
F2 copies a summary of the current tab to the clipboard

or WINMSDP (if you have the resource kit):

Windows NT diagnostics II Reports: Memory use, Services, Devices, IRQ's Ports, Environment variables, Network (rights, transport, stats), Hardware including Display adapter.

Syntax
      WINMSDP option

Key (only one option can be used)

  /a  : ALL prints everything

  /e  : environment
  /d  : drives
  /i  : interrupt resources
  /m  : memory
  /n  : network
  /o  : OS version
  /p  : port resources
  /r  : drivers
  /s  : services
  /u  : DMA resources
  /w  : hardware
  /y  : memory resources
 

The output is very similar to WINMSD if a little more detailed.
The output will appear in a text file called msdrpt.TXT
Edited by forger
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...