Page 1 of 1 1
Topic Options
#82822 - 02/01/11 04:18 PM OSQuery() - Determine what OS using WMI
Kdyer Moderator Offline
Moderator
*****

Registered: 01/01/03
Posts: 6240
Loc: Tigard, OR
NAME OSQUERY

AUTHOR Kent Dyer (leptonator@hotmail.com)

ACTION Returns amount of memory installed from a system using WMI

SYNTAX OSQuery($what,$where)

PARAMETERS $what - What are you querying using WMI
$where - Where is it in WMI

RETURNS EncryptionLevel, LastBootUpTime, Version, CSDVersion, OSType

REMARKS Ref. TotalMem( $Systemname ) - Determine amount of memory installed using WMI
Win32_OperatingSystem

I would like to know how Microsoft query an OS that is not runing DOS or has DOS Emulation!! I know there is DOSEMU for LINUX. [Big Grin] [Big Grin]

DEPENDENCIES Kixtart 4.0, WMI

EXAMPLE and CODE

code:
 BREAK ON
CLS

IF OSQuery("EncryptionLevel","Win32_OperatingSystem") <> "" ? "EncryptionLevel is = "OSQuery("EncryptionLevel","Win32_OperatingSystem")
ENDIF
IF OSQuery("LastBootUpTime","Win32_OperatingSystem") <> "" ? "LastBootUpTime is = "OSQuery("LastBootUpTime","Win32_OperatingSystem")
ENDIF
IF OSQuery("Version","Win32_OperatingSystem") <> "" $Version = OSQuery("Version","Win32_OperatingSystem")
? "Version is = "$Version
ENDIF
IF OSQuery("CSDVersion","Win32_OperatingSystem") <> " " ? "Service Pack is = "OSQuery("CSDVersion","Win32_OperatingSystem")
ENDIF

$ostype = OSQuery("OSType","Win32_OperatingSystem")

SELECT
CASE
$ostype = 0
$ostype = "Unknown"
CASE
$ostype = 1
$ostype = "Other"
CASE
$ostype = 2
$ostype = "MACOS"
CASE
$ostype = 3
$ostype = "ATTUNIX"
CASE
$ostype = 4
$ostype = "DGUX"
CASE
$ostype = 5
$ostype = "DECNT"
CASE
$ostype = 6
$ostype = "Digital Unix"
CASE
$ostype = 7
$ostype = "OpenVMS"
CASE
$ostype = 8
$ostype = "HPUX"
CASE
$ostype = 9
$ostype = "AIX"
CASE
$ostype = 10
$ostype = "MVS"
CASE
$ostype = 11
$ostype = "OS400"
CASE
$ostype = 12
$ostype = "OS/2"
CASE
$ostype = 13
$ostype = "JavaVM"
CASE
$ostype = 14
$ostype = "MSDOS"
CASE
$ostype = 15
$ostype = "WIN3x"
CASE
$ostype = 16
$ostype = "WIN95"
CASE
$ostype = 17 And Left($Version, 3) <> 4.9 $ostype = "WIN98"
$ostype = 17 And Left($Version, 3) = 4.9 $ostype = "WIN9ME"
CASE
$ostype = 18 And Left($Version, 3) = 4.0 $ostype = "WINNT"
$ostype = 18 And Left($Version, 3) = 5.0 $ostype = "WIN2000"
$ostype = 18 And Left($Version, 3) = 5.1 $ostype = "WINXP"
CASE
$ostype = 19
$ostype = "WINCE"
CASE
$ostype = 20
$ostype = "NCR3000"
CASE
$ostype = 21
$ostype = "NetWare"
CASE
$ostype = 22
$ostype = "OSF"
CASE
$ostype = 23
$ostype = "DC/OS"
CASE
$ostype = 24
$ostype = "Reliant UNIX"
CASE
$ostype = 25
$ostype = "SCO UnixWare"
CASE
$ostype = 26
$ostype = "SCO OpenServer"
CASE
$ostype = 27
$ostype = "Sequent"
CASE
$ostype = 28
$ostype = "IRIX"
CASE
$ostype = 29
$ostype = "Solaris"
CASE
$ostype = 30
$ostype = "SunOS"
CASE
$ostype = 31
$ostype = "U6000"
CASE
$ostype = 32
$ostype = "ASERIES"
CASE
$ostype = 33
$ostype = "TandemNSK"
CASE
$ostype = 34
$ostype = "TandemNT"
CASE
$ostype = 35
$ostype = "BS2000"
CASE
$ostype = 36
$ostype = "LINUX"
CASE
$ostype = 37
$ostype = "Lynx"
CASE
$ostype = 38
$ostype = "XENIX"
CASE
$ostype = 39
$ostype = "VM/ESA"
CASE
$ostype = 40
$ostype = "Interactive UNIX"
CASE
$ostype = 41
$ostype = "BSDUNIX"
CASE
$ostype = 42
$ostype = "FreeBSD"
CASE
$ostype = 43
$ostype = "NetBSD"
CASE
$ostype = 44
$ostype = "GNU Hurd"
CASE
$ostype = 45
$ostype = "OS9"
CASE
$ostype = 46
$ostype = "MACH Kernel"
CASE
$ostype = 47
$ostype = "Inferno"
CASE
$ostype = 48
$ostype = "QNX"
CASE
$ostype = 49
$ostype = "EPOC"
CASE
$ostype = 50
$ostype = "IxWorks"
CASE
$ostype = 51
$ostype = "VxWorks"
CASE
$ostype = 52
$ostype = "MiNT"
CASE
$ostype = 53
$ostype = "BeOS"
CASE
$ostype = 54
$ostype = "HP MPE"
CASE
$ostype = 55
$ostype = "NextStep"
CASE
$ostype = 56
$ostype = "PalmPilot"
CASE
$ostype = 57
$ostype = "Rhapsody"
ENDSELECT

? "OSType is = "$OSType

FUNCTION OSQuery($what,$where)
DIM $strquery, $objenumerator, $value
$strquery = "Select $what From $where"
$systemset = GetObject("winmgmts:{impersonationLevel=impersonate}!//@WKSTA")
$objenumerator = $systemset.execquery($strquery)
For Each $objinstance in $objenumerator
IF @error = 0 AND $objinstance <> ""
$=execute("$$value = $$objInstance.$what")
$osquery="$value"+"|"+"$OSQuery"
ENDIF
Next
$osquery=left($osquery,len($osquery)-1)
EXIT @error
ENDFUNCTION



[ 28. October 2003, 16:44: Message edited by: kdyer ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#82823 - 02/01/11 05:09 PM Re: OSQuery() - Determine what OS using WMI
Radimus Moderator Offline
Moderator
*****

Registered: 00/01/06
Posts: 5163
Loc: Tampa, FL
instead of the big select/case statement, why not dump it into a big array ($osarray), and pull the $osarray[$ostype] ??
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#82824 - 02/01/11 05:24 PM Re: OSQuery() - Determine what OS using WMI
Kdyer Moderator Offline
Moderator
*****

Registered: 01/01/03
Posts: 6240
Loc: Tigard, OR
Let's trim this down a bit.. I am sure we can do more..

- Kent

code:

$ostype = OSQuery("OSType","Win32_OperatingSystem")

SELECT
CASE
$ostype = 14
$ostype = "MSDOS"
CASE
$ostype = 15
$ostype = "WIN3x"
CASE
$ostype = 16
$ostype = "WIN95"
CASE
$ostype = 17 AND Left($version, 3) <> "4.9" $ostype = "WIN98"
CASE
$ostype = 17 AND Left($version, 3) = "4.9" $ostype = "WIN9ME"
CASE
$ostype = 18 AND Left($version, 3) = "4.0" $ostype = "WINNT"
CASE
$ostype = 18 AND Left($version, 3) = "5.0" $ostype = "WIN2000"
CASE
$ostype = 18 AND Left($version, 3) = "5.1" $ostype = "WINXP"
CASE
$ostype = 19
$ostype = "WINCE"
ENDSELECT

? "OSType is = "$OSType

FUNCTION OSQuery($what,$where)
DIM $strquery, $objenumerator, $value
$strquery = "Select $what From $where"
$systemset = GetObject("winmgmts:{impersonationLevel=impersonate}!//@WKSTA")
$objenumerator = $systemset.execquery($strquery)
FOR EACH $objinstance IN $objenumerator
IF @error = 0 AND $objinstance <> ""
$=execute("$$value = $$objInstance.$what")
$osquery="$value"+"|"+"$OSQuery"
ENDIF
NEXT
$osquery=left($osquery,len($osquery)-1)
EXIT @error
ENDFUNCTION


[ 11 January 2002: Message edited by: kdyer ]

_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#82825 - 02/01/11 10:30 PM Re: OSQuery() - Determine what OS using WMI
New Mexico Mark Offline
Hey THIS is FUN
****

Registered: 02/01/03
Posts: 223
Loc: Columbia, SC
Hi Kent:

A coupla small suggestions.

1. Networks running 2K/XP/ME workstations will have WMI, as well as those running SMS 2.x (SMS uses WMI to do most of its magic now). However, there are still a lot of systems without WMI installed. If you instantiate the WMI object first, then check the error code immediately after, you can gracefully return an error code if there is a problem before attempting the query.

2. You might want to add a CASE 1 statement and just return "Other OS" for cases you don't cover (or new OS'es added in the future).

These probably seem nitpicky. However, I'm sure that folks on networks with workstations running "Joe's OS" or those without WMI on all workstations would appreciate litle extras like this.

I got a chuckle out of "WINCE"... took me a second on that one.

New Mexico Mark

Top
#82826 - 02/01/11 10:40 PM Re: OSQuery() - Determine what OS using WMI
New Mexico Mark Offline
Hey THIS is FUN
****

Registered: 02/01/03
Posts: 223
Loc: Columbia, SC
Oops... I didn't look closely enough the first time. I thought the function did the SELECT logic.

Have you considered just building an OSType() function?

NMM

Top
#82827 - 02/09/26 06:57 PM Re: OSQuery() - Determine what OS using WMI
Radimus Moderator Offline
Moderator
*****

Registered: 00/01/06
Posts: 5163
Loc: Tampa, FL
this is pretty much a dead subject now that @producttype is available
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
Page 1 of 1 1


Moderator:  Jochen, Radimus, Sealeopard, Bryce, Kdyer, Howard Bullock, Chris S., Glenn Barnas, Allen, Benny69, Mart 
Hop to:
Shout Box

Who's Online
4 registered (tomcoleman, Rickard, Mart, Ask_IT) and 45 anonymous users online.

Generated in 2.641 seconds in which 2.074 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org