Solved

Detect an application instance.

Posted on 2010-08-17
7
400 Views
Last Modified: 2012-05-10
We currently have a simple batch file which when kicked off by the user opens an Excel spreadsheet in a new instance of Excel. The user requirement is to open that file in an existing instance of Excel (it makes it easier for users to copu/paste from one to the other).

Can this be done from a batch file, or do we need to switch a VBScript?
0
Comment
Question by:leonstryker
  • 3
  • 3
7 Comments
 
LVL 5

Expert Comment

by:ploftin
ID: 33457296
I would suggest you switch to VBScript.  It is much more powerful and will do what you need.
0
 
LVL 29

Author Comment

by:leonstryker
ID: 33457476
I know it can be done easialy in VBScript, but would prefer a strictly batch solution to maintain current setup.
0
 
LVL 16

Expert Comment

by:t0t0
ID: 33458829
As far as i'm aware, if you start excel.exe with the command line option /e then invoke a file, followed by another file, both files will open in the single instance of excel.

I have actually tried this in Excel 2007 without the /e command line switch and it still works.

1) have your batch file open an instance of excel by specifying it's full path including the /e switch - something like this:

   "%programfiles%\microsoft office\office12\EXCEL.EXE /E"

2) then open your first excel document by reference (let's say it's called ACCOUNTS.XLS) - something like this:

   "%userprofile%\my documents\accounts\ACCOUNTS.XLS"

3) Now open your second excel document (let's say it's called OLDACC.XLS) - something like this:

   "%userprofile%\my documents\accounts\OLDACC.XLS"

Both XLS documents are now open in a single instance of Excel. You can verify this with the TASKLIST command. It only shows one instance of EXCEL.EXE running.

Putting this all together then, you might have something like this:


   @echo off
   set myfiles=%userprofile%\my documents\accounts

   "%programfiles%\microsoft office\office12\excel.exe /e"

   "%myfiles%\accounts.xls"
   "%myfiles%\oldacc.xls"


This will:

   1) open excel with the /e command line switch.
   2) set a variable (myfiles) to the path of my xls documents
   3) open accounts.xls file
   4) open oldacc.xls file

a simple check with TASKLIST will reveal just one instance of EXCEL.EXE running.




0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 29

Author Comment

by:leonstryker
ID: 33458934
The problem is that the user will likely has an instance of Excel running before the batch starts executing, so doing:
"%programfiles%\microsoft office\office12\excel.exe /e"
would open an additional instance. Not running it we are fine except then the user does not have an instance of Excel open in which case the batch will fail.
Leon
0
 
LVL 16

Accepted Solution

by:
t0t0 earned 500 total points
ID: 33459614
That's not a problem.... Try the rest of the code for now and see if that does the trick...

Alternatively, where the user opens his excel (most likely by clicking a shortcut link to it) edit the shortcut's properites to include the '/e' switch on the command line. At that point, you could also add additional switches including the documents' working folders (always handy) as well as specifying the working directory in the shortcut too.

So for now, leave out the following line

   "%programfiles%\microsoft office\office12\excel.exe /e"

and try opening files by referencing just the files themselves.
0
 
LVL 29

Author Closing Comment

by:leonstryker
ID: 33477400
Just leaving the file without Excel.exe and putting the /e switch after it did the trick. Thank you.
0
 
LVL 16

Expert Comment

by:t0t0
ID: 33478275
oh great stuff. well done. and thank you.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 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

21 Experts available now in Live!

Get 1:1 Help Now