0

I'm looking for a way to be sure it is not already running on some other machine before starting it.

The best way I've figured out is to check for an existing .pid in the MySQL folder.
The easiest thing would be to modify the shortcut but I don't think that's possible afaik. So I need to do a couple of things.

  1. figure out where MySQL is stored
  2. check for the existence of a .pid file and if found the file throw an error stating so with the name of the file MINUS the extension to give them a hint what machine is be running it.
  3. if not exist then go ahead and start wamp like it normally would with the shortcut.

DONE.

If necessary we can ask the user ONCE where wamp is stored then it's simply at %wamp%\bin\mysql I tried this script but it doesn't do it properly, it's opening 2 cmd windows and just throwing a pause. Thanks Bear

@echo off  
cd "C:\google_drive\server\wamp64"
forfiles  /p bin\mysql\ /m *.pid /s /c "cmd /c goto error"
start wampmanager.exe
exit
:error
echo I'm sorry, Mysql is already running so I can't start WAMP for you. Shutdown WAMP on @FNAME before running again."
pause
aschipfl
  • 33,626
  • 12
  • 54
  • 99
Troy Hall
  • 9
  • 3
  • I got a lot of it done and it works now but I haven't figured out how to get the registry key value of the existing Wamp installation so I can use its installation path. What I came up with is.. `@echo off forfiles /p bin\mysql\ /m *.pid /s /c "cmd /c msg * /time:0 I'm sorry, Mysql is already running so I can't start WAMP for you. Shutdown WAMP on @FNAME before running again." && exit start wampmanager.exe ` which requires the bat file be in wamps directory. (sorry for the messy code I couldn't figure out how to make it into a block ) – Troy Hall May 29 '17 at 02:13
  • Is wampmanager a service? If so, you have lots of checking/manipulation options using the sc.exe command. – theglossy1 May 29 '17 at 05:42
  • `forfiles` starts a new command process. `GOTO` from that new process doesn't work (there is no reference / jumping destination). What about `if exist "C:\google_drive\server\wamp64\bin\mysql\*.pid"` instead? – Stephan May 29 '17 at 07:05
  • **THis is just a disaster waiting to happen** Dont attempt to share a WAMPServer instance like this! – RiggsFolly May 29 '17 at 15:59
  • Instead look at a source management system like GIT. – RiggsFolly May 29 '17 at 16:01
  • Oh and by the way, the pid file get ceated in `\wamp64\bin\mysql\mysql\data` – RiggsFolly May 29 '17 at 17:03
  • @RiggsFolly Your statement of a disaster waiting to happen is 100% valid erog my reason for writing this startup routine. While I do use git all the time, I'm not sure that it will work for the purpose of coding on a single system from any device anywhere. Specifically in regard to a LAMP stack. Not to mention most folks would need to have their code public which they may not want. Lastly if you check my script carefully you'll see that I do check the db version data folder. – Troy Hall May 29 '17 at 21:38

1 Answers1

0

You can check the existence of a file with:

if exist "C:\google_drive\server\wamp64\bin\mysql\*.pid

But per your description, I guess, there may be more than one .pid file, so there is a better choice:

setlocal enabledelayedexpansion
set "running="
for %%a in ("C:\google_drive\server\wamp64\bin\mysql\*.pid") do set "running=!running! %%~na,"
if "%running%" neq "" (
  echo I'm sorry, Mysql is already running so I can't start WAMP for you.
  echo Shutdown WAMP on: %running% before running again.
  pause
  goto :eof
)
start wampmanager.exe
Stephan
  • 53,940
  • 10
  • 58
  • 91
  • what does "setlocal" do? How is it beneficial? I like your code, does it create a popup? Here's what I have that IS working but perhaps your version is more elegant. `@echo off forfiles /p bin\mysql\ /m *.pid /s /c "cmd /c msg * /time:0 I'm sorry, Mysql is already running so I can't start WAMP for you. Shutdown WAMP on @FNAME before running again." && exit start wampmanager.exe` Sorry for the messy code I still can't figure out how to get it in an nice block like you guys do. – Troy Hall May 29 '17 at 21:45
  • we need [delayed expansion](https://stackoverflow.com/a/30284028/2152082) for building up the list of servers in the `for` loop. So [setlocal](https://ss64.com/nt/setlocal.html) is necessary. Besides it has another nice effect: all declared variables after `setlocal` are kept local (not permanent, they are gone as soon as the batchfile ends). There is no way to properly format code in a comment. Works for a command or a short line, but is messy for longer snippets of code. – Stephan May 30 '17 at 05:33
  • tyvm sir. You've been a great help. Now all I have to do it get inno setup to work properly. – Troy Hall May 30 '17 at 22:30