Jump to content

vbs / bat to check for reg key and perform if/else


Recommended Posts

My post wasn't intended to correct anything with your scripting method crahak, it was more to example my statement of simplifying the conditional arguments.

Yeah I know. I'm just saying, I did this because I believe that's what he wanted (not that it's necessarily the better way to do it or anything).

Thanks for the cleanup.

Link to comment
Share on other sites


===== Post Nº 1 =====

Wow thanks for all the responses!

The only problem for just checking for 2 conditions is that if IE7 is found as well as SP3, they just can't immediately remove IE7 without first removing SP3. I was wanting the script to be extra wordy to give them specific directions on what to do.

I have so far gotten 2 scripts, the first will show you what SP is installed followed by a message of what IE version is installed. The second script uses an "If xxxxxx then If xxxxx then else" and seems to function fairly well when I only try to look for the presence of an IE version >=7 but upon adding the statements for IE 6 strValue < "7" it fails to execute.

I will be working more with this today and try out the code suggestions that have been made, thank you again!

===== Post Nº 2 =====

So you want to force SP3 as well? As in must be BOTH IE < 7 AND SP3? Ok...

const HKLM = &H80000002
strComputer = "."
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!" & strComputer & "rootdefault:StdRegProv")
Set objWMI2 = GetObject("winmgmts:{impersonationLevel=impersonate}!" & strComputer & "rootcimv2")
Set colItems = objWMI2.ExecQuery("Select * from Win32_OperatingSystem")
strKeyPath = "SoftwareMicrosoftInternet Explorer"
strValueName = "Version"
objWMI.GetStringValue HKLM, strKeyPath,strValueName,strValue
For each elem in colItems
If strValue >= "7" and instr(elem.CSDVersion, "3") Then
MSGBOX "IE 7 and Service Pack 3 were found. You need to go to Control Panel>Add/Remove Programs and remove Service Pack 3 before you can remove Internet Explorer 7. Once completed, reinstall Service Pack 3."
ELSEIf strValue >= "7" and instr(elem.CSDVersion, "2") Then
MSGBOX "IE 7 found! Service Pack 3 NOT found! Please go to Control Panel>Add/Remove Programs and remove Internet Explorer 7 and then install Service Pack 3."
ELSEIf strValue <= "7" and instr(elem.CSDVersion, "2") Then
MSGBOX "IE 7 not found! Service Pack 3 not found! Please install Service Pack 3."
ELSEIf strValue <= "7" and instr(elem.CSDVersion, "3") Then
MSGBOX "IE 7 found! Service Pack 3 Found! No further action is needed."
ELSE
MSGBOX "Unable to determine configuration."
End If
Next

Link to comment
Share on other sites

but upon adding the statements for IE 6 strValue < "7" it fails to execute.

Like I said before...

strValue is a string, 7 should be an integer, but you wrote it as a string comparison... Doesn't work like that.

Looks like you're still trying to do it (in your last post).

However, the script I wrote does EXACTLY what you asked for (it's tested).

If you're doubting Thomas ;) and don't trust the conditional statements, try using combinations of intSP = 2 or intSP = 3, and intIEVers = 6 or intIEVers = 7 (or even intIEVers = 8) just before the if's. You'll see exactly how it behaves for each scenario. Adding an OS check would be a good idea though, unless all your boxes run XP.

Personally instead of myself spending time organizing this project, I think we should be pressing the issue with the web app devs that are obviously behind times with their code.

Absolutely. Nowadays, IE7 has a far bigger market share than IE6 and is still on the rise. And it's been out for a good while now (close to 2 years). There's just no excuse for not having updates/fixes by now, especially when it should only be minor changes required to the web apps in question. Similarly, there's no excuse nowadays for most web apps to not support non-IE browsers. Usually that just means they're using non standard compliant markup that only renders OK in IE, which is very sloppy at best. Some companies seemingly need to work on supporting their products a LOT better... And IE8 will be out soon, and it's not gonna get any better then. And Vista users can't downgrade to crappy IE 6 either, and Vista is quickly gaining market share too...

The only stupid web app I've had the displeasure to see in the last few years that was IE-only, was the web interface for Remedy (thanks to the use of ActiveX junk).

Edited by crahak
Link to comment
Share on other sites

but upon adding the statements for IE 6 strValue < "7" it fails to execute.

Like I said before...

strValue is a string, 7 should be an integer, but you wrote it as a string comparison... Doesn't work like that.

Looks like you're still trying to do it (in your last post).

However, the script I wrote does EXACTLY what you asked for (it's tested).

If you're doubting Thomas ;) and don't trust the conditional statements, try using combinations of intSP = 2 or intSP = 3, and intIEVers = 6 or intIEVers = 7 (or even intIEVers = 8) just before the if's. You'll see exactly how it behaves for each scenario. Adding an OS check would be a good idea though, unless all your boxes run XP.

Personally instead of myself spending time organizing this project, I think we should be pressing the issue with the web app devs that are obviously behind times with their code.

Absolutely. Nowadays, IE7 has a far bigger market share than IE6 and is still on the rise. And it's been out for a good while now (close to 2 years). There's just no excuse for not having updates/fixes by now, especially when it should only be minor changes required to the web apps in question. Similarly, there's no excuse nowadays for most web apps to not support non-IE browsers. Usually that just means they're using non standard compliant markup that only renders OK in IE, which is very sloppy at best. Some companies seemingly need to work on supporting their products a LOT better... And IE8 will be out soon, and it's not gonna get any better then. And Vista users can't downgrade to crappy IE 6 either, and Vista is quickly gaining market share too...

The only stupid web app I've had the displeasure to see in the last few years that was IE-only, was the web interface for Remedy (thanks to the use of ActiveX junk).

Yes crahak thank you, i tested your code and it does just what I need! I was also able to see the syntax of the "if and then" and modify what I had to work as well. With the script i posted in my last post, how can I fix the integer problem you talk about.

Our web app is written by siebel i believe, so frustrating. We also use Altiris HelpDesk which is IE only, doesn't render properly because it fails to recognize firefox as an uplevel browser. This is fixable by tweaking the web.config browsercaps section I just have not had the time to do this. Also the newer version is due out in a few months and I'm sure its been taken care of.

Edited by dfnkt
Link to comment
Share on other sites

And it's been out for a good while now (close to 2 years). There's just no excuse for not having updates/fixes by now, especially when it should only be minor changes required to the web apps in question. Similarly, there's no excuse nowadays for most web apps to not support non-IE browsers. Usually that just means they're using non standard compliant markup that only renders OK in IE, which is very sloppy at best.

Yes :thumbup , programmers should also think about we "poor" users of Opera, Firefox, Konqueror....

jaclaz

Link to comment
Share on other sites

And it's been out for a good while now (close to 2 years). There's just no excuse for not having updates/fixes by now, especially when it should only be minor changes required to the web apps in question. Similarly, there's no excuse nowadays for most web apps to not support non-IE browsers. Usually that just means they're using non standard compliant markup that only renders OK in IE, which is very sloppy at best.

Yes :thumbup , programmers should also think about we "poor" users of Opera, Firefox, Konqueror....

jaclaz

I have been a permanent firefox user since 2004, don't think I could ever go back.

Link to comment
Share on other sites

Yes crahak thank you, i tested your code and it does just what I need! I was also able to see the syntax of the "if and then" and modify what I had to work as well. With the script i posted in my last post, how can I fix the integer problem you talk about.

Well, if you did that, you'd be left with a script that's basically identical to mine. The only real differences, are the messages. Here's the same script again, with your new messages

const HKLM = &H80000002
strComputer = "."
Set objWMI=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "Software\Microsoft\Internet Explorer"
strValueName = "Version"
objWMI.GetStringValue HKLM, strKeyPath,strValueName,strValue
intIEVers = CInt(Left(strValue, InStr(strValue, ".")-1))
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem")
For each elem in colItems
intSP = elem.ServicePackMajorVersion
Next
if intIEVers < 7 and intSP = 3 then
msgbox "IE 7 not found! Service Pack 3 Found! No further action is needed."
elseif intIEVers < 7 and intSP < 3 then
msgbox "IE 7 not found! Service Pack 3 not found! Please install Service Pack 3."
elseif intIEVers > 6 and intSP < 3 then
msgbox "IE 7 found! Service Pack 3 NOT found! Please go to Control Panel>Add/Remove Programs and remove Internet Explorer 7 and then install Service Pack 3."
elseif intIEVers > 6 and intSP = 3 then
msgbox "IE 7 and Service Pack 3 were found. You need to go to Control Panel>Add/Remove Programs and remove Service Pack 3 before you can remove Internet Explorer 7. Once completed, reinstall Service Pack 3."
else
msgbox "Unable to determine configuration."
end if

(also removed the line with blnBadIEVers -- had no use for it, went for actual version checks instead of using the boolean for the conditional statements)

@jaclaz: totally. At a VERY strict minimum, it should work on IE as well as Firefox (that's at least 90% of users out there), but when you have it working on IE and FF, usually there's very little extra work required to test (and make updates) for Opera, Konqueror, Safari (for those poor guys with fruity computers :lol: ) and others. Usually that means standard compliant markup (that works with FF, Opera and all the others), and a IE-specific style sheet or such. I've been a permanent Firefox user for YEARS too (secure, fast, and all them GREAT extensions: the web dev toolbar, firebug, DOM inspector, etc etc)

Anything IE 6 - only is single-platform/windows-only, and even limiting which version of windows can use it (windows only, but even then not all versions!). And that prevents you from updating to a not as sucky version of that browser for your other needs -- you're just stuck with an older version the poorest browser there is (IMO)

Edit: oops, just noticed quoting my posts or copy/pasting from them removed backslashes, very strange... Fixed!

Edited by crahak
Link to comment
Share on other sites

Yes crahak thank you, i tested your code and it does just what I need! I was also able to see the syntax of the "if and then" and modify what I had to work as well. With the script i posted in my last post, how can I fix the integer problem you talk about.

Well, if you did that, you'd be left with a script that's basically identical to mine. The only real differences, are the messages. Here's the same script again, with your new messages

const HKLM = &H80000002
strComputer = "."
Set objWMI=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "Software\Microsoft\Internet Explorer"
strValueName = "Version"
objWMI.GetStringValue HKLM, strKeyPath,strValueName,strValue
intIEVers = CInt(Left(strValue, InStr(strValue, ".")-1))
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem")
For each elem in colItems
intSP = elem.ServicePackMajorVersion
Next
if intIEVers < 7 and intSP = 3 then
msgbox "IE 7 not found! Service Pack 3 Found! No further action is needed."
elseif intIEVers < 7 and intSP < 3 then
msgbox "IE 7 not found! Service Pack 3 not found! Please install Service Pack 3."
elseif intIEVers > 6 and intSP < 3 then
msgbox "IE 7 found! Service Pack 3 NOT found! Please go to Control Panel>Add/Remove Programs and remove Internet Explorer 7 and then install Service Pack 3."
elseif intIEVers > 6 and intSP = 3 then
msgbox "IE 7 and Service Pack 3 were found. You need to go to Control Panel>Add/Remove Programs and remove Service Pack 3 before you can remove Internet Explorer 7. Once completed, reinstall Service Pack 3."
else
msgbox "Unable to determine configuration."
end if

(also removed the line with blnBadIEVers -- had no use for it, went for actual version checks instead of using the boolean for the conditional statements)

@jaclaz: totally. At a VERY strict minimum, it should work on IE as well as Firefox (that's at least 90% of users out there), but when you have it working on IE and FF, usually there's very little extra work required to test (and make updates) for Opera, Konqueror, Safari (for those poor guys with fruity computers :lol: ) and others. Usually that means standard compliant markup (that works with FF, Opera and all the others), and a IE-specific style sheet or such. I've been a permanent Firefox user for YEARS too (secure, fast, and all them GREAT extensions: the web dev toolbar, firebug, DOM inspector, etc etc)

Anything IE 6 - only is single-platform/windows-only, and even limiting which version of windows can use it (windows only, but even then not all versions!). And that prevents you from updating to a not as sucky version of that browser for your other needs -- you're just stuck with an older version the poorest browser there is (IMO)

Edit: oops, just noticed quoting my posts or copy/pasting from them removed backslashes, very strange... Fixed!

Thanks again Crahak, much appreciated. I have used vbscript for a few months and I just don't use it heavily enough to learn all the ins and outs! Thanks for all your help again.

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
  • Recently Browsing   0 members

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