Page 1 of 3

help combining 2 scripts

Posted: Wed Mar 05, 2014 12:24 pm
by jjimenez
I'd like the following script to only put out one result. Either the 64bit app is compliant/non compliant/ or not installed or the 32 bit section is such.
VBScript Code
Double-click the code block to select all.
const HKEY_LOCAL_MACHINE  = &H80000002
on error resume next
Dim dversion, GUIDid

dversion = "6.1.20913.0"
GUIDid = "{89F4137D-6C26-4A84-BDB8-2E5A4BB71E00}"

set oWsh = createobject("wscript.shell")
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")


strKeyPath = "software\microsoft\windows\currentversion\uninstall" 
sDisplayVersion = oWsh.Regread("HKLM\" & strKeyPath & "\" & GUIDid & "\DisplayVersion")
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue

if err.number <>0 then
        wscript.echo "Not-Installed"
        err.clear
    else

If Eval("sDisplayVersion >= dversion") Then
	wscript.echo "Compliant"

Elseif  Eval("sDisplayVersion < dversion") Then
	wscript.echo sDisplayVersion

  End if
End if



strKeyPath = "software\wow6432node\microsoft\windows\currentversion\uninstall" 
sDisplayVersion = oWsh.Regread("HKLM\" & strKeyPath & "\" & GUIDid & "\DisplayVersion")
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue

if err.number <>0 then
        wscript.echo "Not-Installed"
        err.clear
    else

If Eval("sDisplayVersion >= dversion") Then
	wscript.echo "Compliant"

Elseif  Eval("sDisplayVersion < dversion") Then
	wscript.echo sDisplayVersion

  End if
End if
it does both right now, please help me seperate them.

Re: help combining 2 scripts

Posted: Wed Mar 05, 2014 12:35 pm
by jvierra
Sorry but I cannot make sense out of what you are trying to do with you script. It doesn't make much sense.

Did you copy this from somewhere?

Re: help combining 2 scripts

Posted: Wed Mar 05, 2014 12:38 pm
by jvierra
Note that for WMI you need to pick the architecture in advance.

You cannot directly compare strings unless you are sure they are identically formatted.

"1.2.3.4" > "1.2.14.5"


will likely fail.

Re: help combining 2 scripts

Posted: Wed Mar 05, 2014 12:43 pm
by jjimenez
the script works fine.

what i'm trying to do is search one string and if that exists then return a value,

if not then search a different string and if that exists then return a value

if neither exist then error

Re: help combining 2 scripts

Posted: Wed Mar 05, 2014 12:52 pm
by jvierra
This is as close as you will get:
VBScript Code
Double-click the code block to select all.
const HKEY_LOCAL_MACHINE  = &H80000002
 
dversion = "6.1.20913.0"
GUIDid = "{89F4137D-6C26-4A84-BDB8-2E5A4BB71E00}"
set oWsh = createobject("wscript.shell")

On Error Resume Next
strKeyPath = "software\microsoft\windows\currentversion\uninstall"
sDisplayVersion = oWsh.Regread("HKLM\" & strKeyPath & "\" & GUIDid & "\DisplayVersion") 
if err.number <>0 Then
    wscript.echo "Not-Installed in 32 bit registry"
Else
    if(sDisplayVersion >= dVersion) Then
        WScript.Echo "Up to date:" & sDisplayVersion
    Else
        WScript.Echo "Not up to date:" & sDisplayVersion
    End If
    WScript.Quit
End If
 
strKeyPath = "software\wow6432node\microsoft\windows\currentversion\uninstall"
sDisplayVersion = oWsh.Regread("HKLM\" & strKeyPath & "\" & GUIDid & "\DisplayVersion") 
if err.number <> 0 then
    wscript.echo "Not-Installed in 32 bit registry"
else
    if(sDisplayVersion >= dVersion) Then
        WScript.Echo "Up to date:" & sDisplayVersion
    Else
        WScript.Echo "Not up to date:" & sDisplayVersion
    End If
End If

Re: help combining 2 scripts

Posted: Wed Mar 05, 2014 1:02 pm
by jjimenez
thank you very much.

Is there no way to get the error message outside of both queries to where it only returns one value if it errors.

Re: help combining 2 scripts

Posted: Wed Mar 05, 2014 1:27 pm
by jvierra
The copy I posted returns only one line ever. Or it retruns towo messages saying not found.

You can restructure to save the errors until last if you want.

Re: help combining 2 scripts

Posted: Wed Mar 05, 2014 1:35 pm
by jjimenez
can you help me with that? I need it to only return one value ever. Even if it is an error.

Re: help combining 2 scripts

Posted: Wed Mar 05, 2014 2:32 pm
by jjimenez
added a wscript.quit after the first error, fixed it.

Thank you for your time :D

Re: help combining 2 scripts

Posted: Wed Mar 05, 2014 4:02 pm
by jvierra
So you don't ever want to search 32 bit subsytems?

This is all you wanted:
VBScript Code
Double-click the code block to select all.
const HKEY_LOCAL_MACHINE  = &H80000002
  
dversion = "6.1.20913.0"
GUIDid = "{89F4137D-6C26-4A84-BDB8-2E5A4BB71E00}"
set oWsh = createobject("wscript.shell")
 
On Error Resume Next
strKeyPath = "softwaremicrosoftwindowscurrentversionuninstall"
sDisplayVersion = oWsh.Regread("HKLM" & strKeyPath & "" & GUIDid & "DisplayVersion") 
if err.number <>0 Then
    wscript.echo "Not-Installed in 32 bit registry"
Else
    if(sDisplayVersion >= dVersion) Then
        WScript.Echo "Up to date:" & sDisplayVersion
    Else
        WScript.Echo "Not up to date:" & sDisplayVersion
    End If
    WScript.Quit
End If