Solved ( .vbs ) WinOS-Info - help ( if elseif )

Micro-star international / Ms-7510
November 24, 2009 at 20:20:08
Specs: Microsoft Windows XP Professional, 2.4 GHz / 3071 MB
Dim objFS, objShell
Dim strXPKey

Set objShell = CreateObject("WScript.Shell")

' Windows Product Key
strXPKey = objShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName")
If Len(strXPKey) > 0 Then
End If

Function GetKey(rpk)
  Const rpkOffset=52:i=28
  szPossibleChars="BCDFGHJKMPQRTVWXY2346789"
  Do
    dwAccumulator=0 : j=14
    Do
      dwAccumulator=dwAccumulator*256
      dwAccumulator=rpk(j+rpkOffset)+dwAccumulator
      rpk(j+rpkOffset)=(dwAccumulator\24) and 255
      dwAccumulator=dwAccumulator Mod 24
      j=j-1
    Loop While j>=0
    i=i-1 : szProductKey=mid(szPossibleChars,dwAccumulator+1,1)&szProductKey
    if (((29-i) Mod 6)=0) and (i<>-1) then
      i=i-1 : szProductKey="-"&szProductKey
    End If
  Loop While i>=0
  GetKey=szProductKey
End Function

On Error Resume Next 
' Connect to WMI and obtain instances of Win32_OperatingSystem
For Each objOS in GetObject( _
    "winmgmts:").InstancesOf ("Win32_OperatingSystem")

' InstallDate
Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")
    dtmConvertedDate.Value = objOS.InstallDate
    dtmInstallDate = dtmConvertedDate.GetVarDate

keyNTCurrentVersion = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
strWinVersion = objShell.RegRead(keyNTCurrentVersion & "CurrentVersion")
strWinBuildLab = objShell.RegRead(keyNTCurrentVersion & "BuildLab")

' ECHO
WScript.Echo "Product Name: " & VBTAB & objOS.Caption & " " & objOS.OtherTypeDescription & VBCR _
    & "CSD Version: " & VBTAB & objOS.CSDVersion & VBCR & VBCR _
    & "Windows Version:" & vbTab & strWinVersion & vbTab & vbTab & "Build: " & vbTab &objOS.BuildNumber & VBCR _
    & "Build Lab:" & vbTab & vbTab & strWinBuildLab & VBCR & VBCR _
    & "Suite Mask: "  & VBTAB & objOS.SuiteMask & VBCR _
    & "OS Product Suite" & VBTAB &objOS.OSProductSuite & VBCR & VBCR _
    & "Product Type: "  & VBTAB & objOS.ProductType & VBCR _
    & "Product ID: " & VBTAB & objOS.SerialNumber & VBCR _
    & "Product Key: "  & VBTAB & chr(34) & GetKey(objShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId")) & chr(34) & VBCR & VBCR _
    & "Install Date: "  & VBTAB & dtmInstallDate
Next

if Err <> 0 Then
    WScript.Echo Err.Description
    Err.Clear
End if

====================================================================


How do i change the output of ojbOS.ProductType using if elseif ?

OK if ojbOS.ProductType = 1 then i want it to echo "1 - Workstation"
if = 2 then echo " 2 - Domain Controller " and so on

if
1 = "1 - Workstation"
2 = "2 - Domain Controller"
3 = "3 - Server"
"? - Unknown"

Note: I'm still learning vbscripts


See More: ( .vbs ) WinOS-Info - help ( if elseif )

Report •


#1
November 24, 2009 at 21:11:15
✔ Best Answer
are you determined to use IF/ELSE construct? if not, I would set up a small array and use objOStype to reference the correct element:

dim ss(5)
ss(1)="workstation"
ss(2)="domain controller"
ss(3)="server"
ss(4)="unknown"
...
output=objOStype&" - "&ss(objOStype)

or use a CASE construct if vbs supports it
(i'm very much amateur at vbs)


Report •

#2
November 24, 2009 at 21:45:42
I tried the array and i couldn't get it to work but using the CASE construst does seem to work

thanks for the CASE suggestion

nbrane - Thanks for your help


Report •

#3
November 25, 2009 at 00:19:45
code used

' OS Product Type 
OSProductType = objOS.ProductType
Select Case OSProductType
Case "1"
	strOSProductType = "1 - Work Station"
Case "2"
	strOSProductType = "2 - Domain Controller"
Case "3"
	strOSProductType = "3 - Server"
Case Else
	strOSProductType = objOS.ProductType
End Select


Report •

Related Solutions


Ask Question