| 1. |
Solve : Open A specified File if a now > Certain File's Modified stamp? |
|
Answer» Hi The file XYZ.exe - is that a compiled batch file? No, it is a third party software.If the users launch this then it could be all you need. Code: [Select]@echo off :loop If exist Rxyz.tmp echo waiting & timeout 1 & :goto loop start "" xyz.exe Another possible solution is to create a unique random folder, copy xyz.exe into it and launch it. Delete the file and folder when it is done. Everyone would get a separate copy.Quote from: foxidrive on October 01, 2013, 12:00:45 AM If the users launch this then it could be all you need. Thank you, makes sense but the .tmp file name is not always consistent. Therefore, either *.tmp or R*.tmp or ??.tmp if I was sure about the temp file name's length or the original request for a batch file. Also, please confirm that if say, there are 5 PCS on the LAN and more than one user clicks on the short-cut to the new batch file at practically the same time, the batch file will do the needful?Quote from: jds on October 01, 2013, 12:09:20 AM Thank you, makes sense but the .tmp file name is not always consistent. Therefore, either *.tmp or R*.tmp or ??.tmp if I was sure about the temp file name's length or the original request for a batch file. You could use *.tmp if there are no other tmp files in the folder. Quote from: Also, please confirm that if say, there are 5 PCS on the LAN and more than one user clicks on the short-cut to the new batch file at practically the same time, the batch file will do the needful? There is a one second delay. In that time frame there could be a clash with multiple users. The other suggestion I made would solve that for any number of users, if the file can be executed in another folder.Quote from: foxidrive on October 01, 2013, 08:32:33 AM
While trying to find a solution by code such as requested here, the workaround I use is to have the executable itself saved with different names - 'XYZ.exe', "XYZ1.exe', 'XYZ2.exe' etc. and have different computer's short-cuts point to unique software executables. But this is a workaround. Would dearly like to find a code solution to this problem.In that case it's a little simpler. This is meant to A) generate a random number, B) copy the XYZ executable to that new name and launch it, C) wait until the program is closed and then delete the temporary copy. A drawback is that an extra cmd window will be on the desktop while the XYZ program is active. Code: [Select]@echo off :loop set "num=xyz-temp-%random%%random%%random%.exe" If exist "%num%" goto :loop copy "xyz.exe" "%num%" >nul echo This window will automatically close when XYZ is ended - don't close it manually. start "" /w "%num%" del "%num%" One workaround for the cmd window is to launch the files normally - and in a scheduled task remove all the temporary executables once a day. Code: [Select]@echo off :loop set "num=xyz-temp-%random%%random%%random%.exe" If exist "%num%" goto :loop copy "xyz.exe" "%num%" >nul start "" "%num%" This batch file will remove all the temporary executables. Code: [Select]@echo off del "d:\folder\xyz-temp-*" Quote from: foxidrive on October 01, 2013, 09:26:37 AM In that case it's a little simpler. This is meant to Not sure if Solution #1 will work when USED by multiple users at the same time (beside being ugly). With Solution #2, can it be modified to remove previously created temporary exes whenever the batch file is run from any LAN PC? Sort of checking for temp files and if they are not open to delete them. The question still not answered adequately is, "Will the batch file code work when executed by more than one user at precisely the same time?" Say PC1 executes 'openfile.bat' and at the same time user on PC2 double-clicks the short-cut to 'openfile.bat' - it nothing happens (as in nothing adverse) when PC2 user double-clicks, it is OK with me. He will simply try again after a few seconds thinking that he has not double-clicked properly. Solution #3 ?? Is there any code that can execute this way - When the 'Openfile.bat' file is executed, a run on time (now+2 seconds = x) is executed to open 'XYZ.exe' at time x and 'Openfile.bat' closes. If 'Openfile.bat' is accessed again, it fetches x and executes a run on time command (now + 2 seconds or x+2 seconds, whichever is later) and 'Openfile.bat' closes. I imagine that 'Openfile.bat' will open, run and close in milliseconds, even over a LAN. In this way there is a pre-defined settable minimum interval between the open attempts of 'XYZ.exe' |
|