help combining 2 scripts

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 10 years and 3 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
jjimenez
Posts: 12
Last visit: Fri Mar 07, 2014 8:23 am

help combining 2 scripts

Post 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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: help combining 2 scripts

Post 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?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: help combining 2 scripts

Post 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.
User avatar
jjimenez
Posts: 12
Last visit: Fri Mar 07, 2014 8:23 am

Re: help combining 2 scripts

Post 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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: help combining 2 scripts

Post 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
User avatar
jjimenez
Posts: 12
Last visit: Fri Mar 07, 2014 8:23 am

Re: help combining 2 scripts

Post 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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: help combining 2 scripts

Post 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.
User avatar
jjimenez
Posts: 12
Last visit: Fri Mar 07, 2014 8:23 am

Re: help combining 2 scripts

Post by jjimenez »

can you help me with that? I need it to only return one value ever. Even if it is an error.
User avatar
jjimenez
Posts: 12
Last visit: Fri Mar 07, 2014 8:23 am

Re: help combining 2 scripts

Post by jjimenez »

added a wscript.quit after the first error, fixed it.

Thank you for your time :D
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: help combining 2 scripts

Post 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
This topic is 10 years and 3 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked