dfnkt Posted June 18, 2008 Share Posted June 18, 2008 I am currently trying to write a batch file to query the registry to determine if internet explorer 7 is installed and echo a message to the user appropriately.The path in the registry is HKLM\Software\Microsoft\Internet Explorer\Version Vector The key is: "IE"IE 7 has a value of "7.0000" and 6 has a value of "6.0000". I am trying to develop a batch (wouldn't be opposed to VBS) to echo a msg to the user regarding what was found. By simply using@ECHO OFFREG QUERY "HKLM\Software\Microsoft\Internet Explorer\Version Vector" /v IEI can see what the value is but I would like to do something such as piping the key into find and evaluating it like so@ECHO OFFREG QUERY "HKLM\Software\Microsoft\Internet Explorer\Version Vector" /v IE |Find /I /C "7.0000"IF (%ERRORLEVEL% NEQ 0 GOTO noie7) ELSE (goto foundie7):noie7ECHO Internet Explorer 7 Not Found!:foundie7ECHO Internet Explorer 7 FOUND!PAUSEI have tried this exact batch only to get errors. It doesn't seem to want to recognize the ELSE part of the statement and just always says IE7 found regardless of what is actually present. I also looked at using vbs/wmi but I was unable to find the root\cimv2 or otherwise class for "add/remove" programs.Help? Link to comment Share on other sites More sharing options...
CoffeeFiend Posted June 18, 2008 Share Posted June 18, 2008 I wouldn't exactly recommend using HKLM\Software\Microsoft\Internet Explorer\Version Vector as it doesn't even exist on my box (not on this one anyhow, haven't checked the others).You could do something like this:const HKLM = &H80000002strComputer = "."Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")strKeyPath = "Software\Microsoft\Internet Explorer"strValueName = "Version"oWMI.GetStringValue HKLM,strKeyPath,strValueName,strValueMsgBox "IE Version: " & strValueif you prefer a jscript, or powershell version, or whatever else, just askKeep in mind IE8 is coming out soon too (beta 1 is already out), so testing for IE 7 only might be shortsighted.I find .cmd/.bat works best for very simple things, but as soon as it's past basic command lines, a scripting language is far better (more versatile/powerful). Link to comment Share on other sites More sharing options...
dfnkt Posted June 18, 2008 Author Share Posted June 18, 2008 We have line of business apps that do not have any support for IE 7 let alone IE 8 (or vista for that matter) anywhere in sight. The purpose of this is to make it easier for our helpers who are less technically inclined at an upcoming conference determine if IE7 is installed (which they need to remove).Thanks for the reply and I will take a look at it. Link to comment Share on other sites More sharing options...
Scr1ptW1zard Posted June 18, 2008 Share Posted June 18, 2008 With a little change, your script will work:@ECHO OFFREG QUERY "HKLM\Software\Microsoft\Internet Explorer\Version Vector" /v IE |Find /I /C "7.0000">nulIF %ERRORLEVEL% NEQ 0 ( ECHO Internet Explorer 7 Not Found!) ELSE ( ECHO Internet Explorer 7 FOUND! )PAUSE Link to comment Share on other sites More sharing options...
dfnkt Posted June 18, 2008 Author Share Posted June 18, 2008 (edited) Thanks guys! One final question, I've pieced the IE7 detection together with a service pack detection script I had written. I have the two working together however how would you make it so that checks if IE7 and SP3 are installed and THEN gives you a msg box telling you that you need to uninstall SP3/ Then uninstall IE7?Here is the whole script I'm working with now:const HKLM = &H80000002strComputer = "."Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")Set objWMI2 = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colItems = objWMI2.ExecQuery("Select * from Win32_OperatingSystem")strKeyPath = "Software\Microsoft\Internet Explorer"strValueName = "Version"objWMI.GetStringValue HKLM, strKeyPath,strValueName,strValueIf strValue >= "7" ThenMSGBOX "IE 7 Found! Please Go To Control Panel>Add/Remove Programs and Remove It."ELSEIf strValue >= "6" ThenMSGBOX "IE 7 Not Found! You are OK!"End IfEnd IfFor each elem in colItemsIf instr(elem.CSDVersion, "2") Thenmsgbox "Found Service Pack2"ElseIf instr(elem.CSDVersion, "3") Thenmsgbox "Found Service Pack3"End IfEnd IfNextBasically What this does now is says "Hey IE7 is installed, remove it" then it tells you which SP is present. Can it be coded to determine if there is a combination of both SP3 / IE7 and then give them a message box to the effect of "IE7 AND Service Pack 3 was found. You will need to remove Service Pack3 before removing IE7.I assume its possible, I just seem to have lost my thinking cap today. Edited June 18, 2008 by dfnkt Link to comment Share on other sites More sharing options...
CoffeeFiend Posted June 18, 2008 Share Posted June 18, 2008 You can't do If strValue >= "7" ThenstrValue is a string, 7 should be an integer, but you wrote it as a string comparison... Doesn't work like that.How about this?const HKLM = &H80000002strComputer = "."Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")strKeyPath = "Software\Microsoft\Internet Explorer"strValueName = "Version"objWMI.GetStringValue HKLM, strKeyPath,strValueName,strValueintIEVers = CInt(Left(strValue, InStr(strValue, ".")-1))if intIEVers > 6 then blnBadIEVers = true else blnBadIEVers = falseSet objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem")For each elem in colItems intSP = elem.ServicePackMajorVersionNextif intIEVers < 7 then msgbox "Evrything OK!"elseif intSP < 3 then msgbox "IE " & CStr(intIEVers) & " Found! Please Go To Control Panel>Add/Remove Programs and Remove It."else msgbox "IE " & CStr(intIEVers) & " and SP" & CStr(intSP) & " Found! Please Go To Control Panel>Add/Remove Programs and Remove It." end ifThis checks for IE vers > 6 and blindly SP > 2 (regardless of if it's win2k, xp, or vista -- assuming all your boxes run XP here)SP3 might have been installed before IE7 though, in which case, one shouldn't have to remove SP3. Link to comment Share on other sites More sharing options...
dfnkt Posted June 18, 2008 Author Share Posted June 18, 2008 Will try the code out! But thanks to microsoft once SP3 is installed, IE 7 is locked onto a machine.http://blogs.msdn.com/ie/archive/2008/05/0...-and-xpsp3.aspx Link to comment Share on other sites More sharing options...
dfnkt Posted June 18, 2008 Author Share Posted June 18, 2008 (edited) Is there not a way to make a vbscript look at multiple if's before having to "then"?If SP3 and IE7 found then msgbox "remove sp3, then remove ie7, reinstall sp3"if sp2 and IE7 found thenmsgbox "remove ie7 then install sp3"if SP3 and IE6 found thenmsgbox "no further action needed"if sp2 and ie6 found thenmsgbox "please install sp3"^^ something like that? Edited June 18, 2008 by dfnkt Link to comment Share on other sites More sharing options...
jaclaz Posted June 18, 2008 Share Posted June 18, 2008 Is there not a way to make a vbscript look at multiple if's before having to "then"?If SP3 and IE7 found then msgbox "remove sp3, then remove ie7, reinstall sp3"if sp2 and IE7 found thenmsgbox "remove ie7 then install sp3"if SP3 and IE6 found thenmsgbox "no further action needed"if sp2 and ie6 found thenmsgbox "please install sp3"^^ something like that?Not what you asked, but this is how I would do that in batch:...REM routine to set variable found_somethingREM If found SP2 SET /A found_something=20REM If found SP3 SET /A found_something=30REM If found IE6 SET /A found_something=%found_something%+6REM If found IE7 SET /A found_something=%found_something%+7GOTO :found%found_something%:found37ECHO remove sp3, then remove ie7, reinstall sp3GOTO :EOF:found27ECHO remove ie7 then install sp3GOTO :EOF:found36ECHO no further action neededGOTO :EOF:found26ECHO please install sp3GOTO :EOFjaclaz Link to comment Share on other sites More sharing options...
CoffeeFiend Posted June 18, 2008 Share Posted June 18, 2008 (edited) So you want to force SP3 as well? As in must be BOTH IE < 7 AND SP3? Ok...const HKLM = &H80000002strComputer = "."Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!" & strComputer & "rootdefault:StdRegProv")strKeyPath = "SoftwareMicrosoftInternet Explorer"strValueName = "Version"objWMI.GetStringValue HKLM, strKeyPath,strValueName,strValueintIEVers = CInt(Left(strValue, InStr(strValue, ".")-1))if intIEVers > 6 then blnBadIEVers = true else blnBadIEVers = falseSet objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!" & strComputer & "rootcimv2")Set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem")For each elem in colItems intSP = elem.ServicePackMajorVersionNextif intIEVers < 7 and intSP = 3 then msgbox "no further action needed"elseif intIEVers < 7 and intSP < 3 then msgbox "please install sp3"elseif intIEVers > 6 and intSP < 3 then msgbox "remove ie7 then install sp3"else msgbox "remove sp3, then remove ie7, reinstall sp3" end ifAnything else... just ask. (Normally I use the .wsf format, and I sign them, and add a few comments)<Edit>PowerShell version of the same, should anyone care:$MachineName = "."$SP = (Get-WmiObject -Class win32_OperatingSystem -namespace "rootCIMV2" -ComputerName $MachineName).ServicePackMajorVersion$IE = (Get-ItemProperty 'HKLM:SoftwareMicrosoftInternet Explorer').Version.Split(".")[0]if ($IE -lt 7 -and $SP -ge 3) { write-host "Everything OK!" } elseif ($IE -lt 7 -and $SP -lt 3) { write-host "Install SP3" } elseif ($IE -ge 7 -and $SP -lt 3) { write-host "Uninstall IE7" } elseif ($IE -ge 7 -and $SP -ge 3) { write-host "Uninstall SP3 then uninstall IE7" }else { write-host "This case shouldn't ever happen" }It's a lot nicer and more concise, but you do need PowerShell installed (if you want MessageBoxes instead of text, then use the .popup method of the script.shell object)</Edit> Edited June 19, 2008 by Yzöwl Link to comment Share on other sites More sharing options...
frodo Posted June 18, 2008 Share Posted June 18, 2008 Why not use AutoIt for this, the bonus apart from easier conditional programming is that you get a gui, so you dont have to suffer console screens...... Link to comment Share on other sites More sharing options...
Yzöwl Posted June 18, 2008 Share Posted June 18, 2008 Is there any real need for the if this do this and this type messages?If you want to make things as simple as possible for your helpers, just give them a single task not a possible list of themYou've only got to check for two conditions:If Internet Explorer is version 7 then uninstall it!If Service Pack is not 3 then install SP3Using the most common language in the thread thus far, I'd suggest an idea similar to this:strComputer = "."Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")For Each objItem in colItems If InStr(objItem.Caption, "Windows XP") Then strSP = objItem.ServicePackMajorVersion Else Wscript.Echo "This computer is not running Windows XP" Wscript.Quit End IfNextSet objWMIService = GetObject("winmgmts:\\" & strComputer & _ "\root\cimv2\Applications\MicrosoftIE")Set colIESettings = objWMIService.ExecQuery("Select * from MicrosoftIE_Summary")For Each strIESetting in colIESettings IEVer = split(strIESetting.Version, ".")NextIf IEVer(0) = "7" Then WScript.Echo "Remove IE7" Wscript.QuitElseIf strSP = "3" Then Wscript.Echo "No action needed"Else WScript.Echo "Install SP3"End IfNotice the check for XP first! Link to comment Share on other sites More sharing options...
CoffeeFiend Posted June 19, 2008 Share Posted June 19, 2008 Why not use AutoIt for this, the bonus apart from easier conditional programming is that you get a gui, so you dont have to suffer console screens......AutoIt isn't exactly the best/most universal/most well known scripting kit. It's meant mostly to automate button clicks and such, which a LOT of ppl see as a last resort. And it needs the program installed to run scripts, whereas WSH is already installed on most PCs. With most network admin types (windows world, not linux), vbscript is pretty much the de facto standard, slowly being replaced by PowerShell. There are no console messages with vbscript (using wscript -- as long as you didn't force it to use cscript).Yzöwl: Likely, he wants a messagebox popup for the end-users, and only one of them, hence all the nested if's. But yeah, my script blindly checked for SP and not OS like I said before (assuming he uses only XP)Also, opening \root\cimv2\Applications\MicrosoftIE throws an exception here, hence why I went with the other method (reading from registry directly). Screenshot of debug session in VS: Link to comment Share on other sites More sharing options...
frodo Posted June 19, 2008 Share Posted June 19, 2008 Perhaps you need to visit autoItscript.com and you'll see its not as you describe "mostly to automate button clicks" and also not "a LOT of ppl see as a last resort". Ive written entire applications using it, including a Ghost clone thats indistinguishable form the real thing in every detail Its as powerful, if not more, no actually more, than anything you can come up with in a console, its free and is growing all the time due to one of the most active forums on the net.And it DOES NOT need any program installed to run it, you complie your scripts to an .exe file. Link to comment Share on other sites More sharing options...
Yzöwl Posted June 19, 2008 Share Posted June 19, 2008 Okay boys, playtime's over, lets stick to programming/scripting.All other stuff removed!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. Ther helper runs the script it tells them what to do next. They run the script after doing that it'll let them know their next move. I think from my experience of helpers that if you just give on task at a time it saves your hair. All they need to learn to do is run script, follow advice, run script, follow advice Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now