Solved

Detect IE version from batch file or command script

Posted on 2007-03-21
16
3,066 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
16 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18769098
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
ID: 18769115
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
ID: 18769121
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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 67

Expert Comment

by:sirbounty
ID: 18769132
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
ID: 18769133
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
ID: 18769137
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
ID: 18769145
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
ID: 18769149
Good luck to you... : ^)
0
 
LVL 4

Author Comment

by:johndeerb
ID: 18774025
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
ID: 18774076
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
ID: 18774077
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
ID: 18774099
Glad to hear it :)
Though the HKLM should also work...
0
 
LVL 4

Author Comment

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

Expert Comment

by:sirbounty
ID: 18774116
Happy to help> :^)
Thanx for the grade!
0
 

Expert Comment

by:arshad shaik
ID: 41782136
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
ID: 41785176
Maybe cliinfo or systeminfo would provide you some of that detail.  I suppose you could scrub the registry for anything omitted?
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Suggested Courses

739 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