Solved

Detect IE version from batch file or command script

Posted on 2007-03-21
16
2,764 Views
Last Modified: 2016-09-05
I have a .cmd script built for an installer application, and I need to be able to detect what version of Internet Explorer is on the PC from within the script.  I thought about using reg.exe to output the registry key to a temporary .txt file and then reading the file to find the version key.  This seems klunky to me and I don't really like poking around in the users registry or creating files on their machines.  Can anyone think of a cleaner way?
0
Comment
Question by:johndeerb
  • 9
  • 6
16 Comments
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Are you opposed to a vbscript method?

This will echo the version to the screen (2 lines).

Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
wscript.echo objFSO.GetFileVersion("C:\Program Files\Internet Explorer\iexplore.exe")


What do you need to do with the version data?
You can run a script based upon the version...

Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objShell: Set objShell=CreateObject("Wscript.Shell")
IEVersion=objFSO.GetFileVersion("C:\Program Files\Internet Explorer\iexplore.exe")
Select Case IEVersion
  Case "6.0.2900.2180" 'IE6
    objShell.Run "c:\ie6.bat"
  Case Else 'not IE6
    objShell.Run "c:\otherIE.bat"
End Select

Or, you can simply write it to a text file...

Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
IEVersion=objFSO.GetFileVersion("C:\Program Files\Internet Explorer\iexplore.exe")
Dim objFile: Set objFile=objFSO.CreateTextFile("C:\IEVersion.txt")
objFile.WriteLine IEVersion
objFile.Close
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
Comment Utility
The above, obviously, assumes that iexplore is installed in the default location.

The command-line 'reg' version would be simply:

reg query "hklm\software\microsoft\internet explorer" /v Version

And you could get a varialbe with the version by using:

for /f "skip=2 tokens=3" %a in ('reg query "hklm\software\microsoft\internet
 explorer" /v Version') do set IEVer=%a

or, if placing in a batch file: (double up on the %s)

for /f "skip=2 tokens=3" %%a in ('reg query "hklm\software\microsoft\internet
 explorer" /v Version') do set IEVer=%%a

But, this limits the user to having admin permissions - which most users don't...so they won't be able to read the hklm string.

However, you can do so from a remote workstation using

for /f "skip=2 tokens=3" %%a in ('reg query "\\ComputerA\hklm\software\microsoft\internet
 explorer" /v Version') do set IEVer=%%a

or even loop through a list of computers like:

For /f %%a in (C:\Computers.txt) do call :process %%a
goto :eof

:process
Set pc=%1
for /f "skip=2 tokens=3" %%x in ('reg query "\\%pc%\hklm\software\microsoft\internet
 explorer" /v Version') do echo %pc% has IE version %%a >> C:\IE_Results.txt
0
 
LVL 4

Author Comment

by:johndeerb
Comment Utility
Your lightening fast, sir...

I am making a CD to send out for a simple task to build a connection to an unpublished IP web application.  It will autorun a html file with links to steps in the connection, one of which is to install IE6 if needed.  The app requires >= IE6, so I want to detect the version and if needed, launch the ie6 installer.  The problem is that our folks don't want me to have anything on the page that requires the user to have their IE security set to allow scripting.  SO, I thought if I just linked to a local .cmd script from the welcome page then it won't matter if their browsers allow scripting to run on the welcome page...
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Hmm - I don't know that the scripting methods above will help you then...
What language are you using for the app?
0
 
LVL 4

Author Comment

by:johndeerb
Comment Utility
Does the user have to be a local admin to read from any key in the registry?  HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet explorer for example...
(Sorry I am not a real registry guru...)
Thanks!
jb
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
HKLM - is the Local Machine - yes, the user would need admin access (85% sure of that...)

HKCU - no, this is the Current User key and the user typically has full rights to this hive.  

You 'may' get read access to the hklm using reg.exe, but I doubt it...
I don't know much about your app or procedures here, but I wonder if you couldn't script something to automate that simple reg query under the local system credentials...just have System output the detail to a text file for you - maybe to the global %temp% path...
0
 
LVL 4

Author Comment

by:johndeerb
Comment Utility
The app is a canned solution from a vendor.  My task is just to build a connection to get folks into it.  I have redirected a couple of IP addresses on our firewall, so now I need to send a simple installer out to get folks up to requirements (IE6, java 1.4.2) and allow a connection(add 2 entries into hosts file).  Since IE now blocks scripts from running on the page by default, I was afraid to use vbscript to handle the install because I don't want a bunch of phone calls from folks who don't notice the yellow bar.

Maybe I'll test tomorrow on some machines in house and verify whether a non-admin user can query the registry keys you mentioned.  If that don't work, I guess it's vbscript and strict instructions, huh?

Thanks!!
jb
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Good luck to you... : ^)
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 4

Author Comment

by:johndeerb
Comment Utility
Looks like any user can query the HKLM keys using reg.exe but I'm having trouble getting the variable assignment to stick.  I ran your code:
for /f "skip=2 tokens=3" %%a in ('reg query "hklm\software\microsoft\internet
 explorer" /v Version') do set IEVer=%%a
in a command script followed by a line:
ECHO %IEVer%
and didn't get an echo.  Am I missing something?
Thanks!
jb
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
If you run it from a command line, only use one % sign...

for /f "skip=2 tokens=3" %a in ('reg query "hklm\software\microsoft\internet
 explorer" /v Version') do set IEVer=%a
0
 
LVL 4

Author Comment

by:johndeerb
Comment Utility
Never mind.. I'm an idiot.

I changed the code to:
for /f "skip=2 tokens=3" %%a in ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer" /v Version') do set IEVer=%%a

ECHO Version is %IEVer%

and it is kind enough to echo the actual version number.

Thanks!!!
jb
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Glad to hear it :)
Though the HKLM should also work...
0
 
LVL 4

Author Comment

by:johndeerb
Comment Utility
Thanks again, sir...
I'd give you an A+ if there was one.
jb
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Happy to help> :^)
Thanx for the grade!
0
 

Expert Comment

by:arshad shaik
Comment Utility
Hi sir bounty ..Im working with IT security team so i need to login into all my server and need to take print screen of IE version details and SEP version details Windows update print screen ..is this possible to get this all the info by run batch file or script
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Maybe cliinfo or systeminfo would provide you some of that detail.  I suppose you could scrub the registry for anything omitted?
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now