We help IT Professionals succeed at work.
Get Started

Set Active Window

fwecoadmin asked
Last Modified: 2012-06-27
OK here goes...
My compnay uses a docmuent management app called Solidworks PDM Enterprise. This app has a feature called dispatch that will launch any app or script that I throw at it and will do so only when a file in the vault has changed to a particular state such as when it enters "work in progress".

My task is to have the dispatch launch a command\script that will do the following:

Note: %Filepath%, %PathtoPDFS% and %filename% are variables that I created in PDM.
The most important one is %filename%.

*This triggers the first part of the action script
when %filename%.prt enters "work in progress" then

*This will close the connection to the file on the server
cmd /c \\Servername\c$\pstools\Psfile.exe \\Servername "%PathtoPDFs%%filename%.pdf" -c

*This will delete the file
delete %filepath%%filename%.pdf

*This will launch a batch file on the remote clients pc
\\Servername\c$\pstools\psexec @hosts.txt -i -s cmd.exe /c c:\taskkill.bat %filename%

*This is the batch file. It closes whatever application the client was using to view the file
echo off
Taskkill.exe /FI "WINDOWTITLE eq %1.*"

My problem is that Taskkill.exe /FI "WINDOWTITLE eq %1.*" will only work if the app that has the file open is the active window. So if the user has file %filename%.pdf open and they have Adobe Reader minimized then taskkill connot read the windowtitle. I was thinking that a vbscript could help and found a few things on the web refering to setactivewindow and setforegroundwindow. I think this may work but im not sure how to go about writing it. Im somewhat familiar with vb script but I've never written anything quite like this. In short I need help!

P.S. I need to be able to launch the script like this:
"c:\windows\system32\wscript\script.vbs %filename%"  where %filename% is NOT a static filename. Disptach will pass the filename to the script.


Watch Question
Top Expert 2010
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE