Click here to Skip to main content
15,905,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Scenario:

A webpage posts a method "Initiate" to server.php file. The server.php file will launch the application "TestDlg.exe".


Code:

PHP
if (isset($_POST['Initiate']))
{
      $shell = new COM("WScript.Shell") or die("Requires Windows Scripting Host");
      $exePath = "TestDlg.exe";
      $shell->exec($exePath); //this is launching the application successfully
}


What i need:

Multiple instances of TestDlg.exe are launched each time i post "Initiate". Instead of launching "TestDlg.exe" always, is there any way to check if "TestDlg.exe" is already launched and then launch if it is not launched?

**** I cannot edit the application "TestDlg.exe", i do not have the rights. So please don't tell me to kill any new instances of the TestDlg.exe in the application itself. I want to handle this in php.
Posted

It's not that easy, but if "TestDlg.exe" is your code, you should embed the recognition in this code instead of relying on some external process, develop in PHP or not. I'll explain why. You don't have enough information. You can request all processes being executed by the OS at some moment, but essentially, all you get is the set of some IDs (process and threads) and strings (names). This would not be 100% reliable, because you always have a chance that some unrelated processes have, say, identical names, just by accident.

In contrast, if you embed the recognition on your application, you can develop a very robust technique. The approach is not to detect anything, but to exist the second instance immediately and pass data (if any) to the first instance. I have a very robust solution and explain all the ideas in my past answers:
Custom Windows right-click command launching multiple instances[^],
Enter multiple commands to only one process instance[^].

Unfortunately, I have no idea what is your platform and language, so my information may be not 100% relevant, but you could use some ideas. Next time, please share such important detail.

(I mean, "PHP" and "Windows" is not enough. You need to provide information on "TestDlg.exe".)

—SA
 
Share this answer
 
Comments
amarasat 31-Oct-13 10:57am    
The easy solution i found for this one is trying to delete the TestDlg.exe file before launching it. If i was able to delete it, then copy it back from the backup file and launch it.

If i cannot delete it, that means its already running. Its working fine; just let me know if u see any issue with it.
Sergey Alexandrovich Kryukov 31-Oct-13 12:41pm    
This is a really bad solution. And what I advice is the most comprehensive one. If TestDlg.exe is not your code (is it?), the best solution would be not using this application.
—SA
The easy solution i found for this one is trying to delete the TestDlg.exe file before launching it. If i was able to delete it, then copy it back from the backup file and launch it.

If i cannot delete it, that means its already running. Its working fine; just let me know if u see any issue with it.
 
Share this answer
 
Comments
Seboka Matsoso 16-Apr-14 15:37pm    
Huh!! Funny but correct solution...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900