Please do NOT post requests for help here. Use the Help forum for that.

TOPIC: webtrees and VBS

webtrees and VBS 1 year 5 months ago #1

  • dhwtrees
  • dhwtrees's Avatar
  • Offline
  • New
  • Posts: 23
I am using a VBS to launch XAMPP/webtrees as localhost:
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
Set colProcessList = GetObject("Winmgmts:").ExecQuery ("Select * from Win32_Process")

For Each objProcess in colProcessList
If objProcess.name = "xampp-control.exe" then
procxampp = True
Exit For
End if
Next

If not procxampp then
objShell.Run("C:/xampp/xampp-control.exe")
End if

objShell.Run("http://localhost/webtrees/login.php?url=index.php%3Fctype%3Dgedcom%26ged%3DWalton%2520WT")

Set objShell = Nothing
Set colProcessList = Nothing

Does anyone know how to check if webtrees is already running i.e. to avoid the multiple instances that the above will create if run more than once?

Thanks David
The administrator has disabled public write access.

webtrees and VBS 1 year 5 months ago #2

  • fisharebest
  • fisharebest's Avatar
  • Offline
  • Administrator
  • Posts: 11034
I'm afraid my knowledge of microsoft tools and products is virtually zero.

This sounds more like a question to ask on a VBS support forum than the webtrees forum.

The people here are mostly genealogists, rather than developers.
Greg Roach - This email address is being protected from spambots. You need JavaScript enabled to view it. - fisharebest.webtrees.net
The administrator has disabled public write access.

webtrees and VBS 1 year 5 months ago #3

  • bertkoor
  • bertkoor's Avatar
  • Offline
  • Gold
  • Greetings from Utrecht, Holland
  • Posts: 1545
It's been a while since I've done any vb-scripting, lately I favoured PowerShell for that kind of tasks. Both can accomplish the same though. I've now switched to a Mac computer, so at the moment I cannot even try these things out.

What I had been doing on my own Windows PC was just have a shortcut to the XAMPP Control Panel on my desktop. From there I'd start the Apache and MySql processes manually and click in my browser on the webtrees from Favourites. Then whenever I was finished I'd go back to the Xampp Control Panel and stop it there. So your script is somewhat more ambitious.

dhwtrees wrote:
Does anyone know how to check if webtrees is already running

This part here of your script:
For Each objProcess in colProcessList
   If objProcess.name = "xampp-control.exe" then
      procxampp = True
      Exit For
   End if
Next
should presumably set procxampp to True if the xampp control panel is running. However the process you should rather be looking for is the Apache HTTP/D server. Because opening the Control Panel could automagically start it, but there's no guarantee it will.

Instead of looping through all the processes you'd better ask via the query what the process name is you're interested in.
Also I'd rather look for the background processes httpd.exe and mysqld.exe which are started by the control panel.
My guess is it won't hurt to start these again, since these are daemon processes.
And since there are two processes, the checking can be done by a function which can do it for any process.
Also the url of the page you open in the default browser can be shorter. login.php will by default redirect you back to index.php for the default tree.

So this is the vbscript I came up with:
Function isNotRunning(processName)
  Set colProcessList = GetObject("Winmgmts:").ExecQuery ("Select * from Win32_Process where Name='" & processName & "'")
  isNotRunning = (colProcessList.count == 0)
End Function

Set objShell = WScript.CreateObject("WScript.Shell")
If isNotRunning("httpd.exe")
   objShell.Run("c:\xampp\apache\bin\httpd.exe")
End If
If isNotRunning("mysqld.exe")
   objShell.Run("c:\xampp\mysql\bin\mysqld.exe --defaults-file=mysql\bin\my.ini --standalone --console")
End If
objShell.Run("http://localhost/webtrees/login.php")

This is inspired a bit by the apache_start.bat and mysql_start.bat batch scripts normally shipped with XAMPP.
Note that no effort is put in checking for errors. Apache and Mysql can be left running, and you should be able to start the script multiple times.
Then all that's left of the functionality is opening the webtrees page in your browser.

If you want to stop apache / mysqld, you could do so by a simular script (inspired on apache_stop.bat & mysql_stop.bat)
Function isRunning(processName)
  Set colProcessList = GetObject("Winmgmts:").ExecQuery ("Select * from Win32_Process where Name='" & processName & "'")
  isRunning = (colProcessList.count > 0)
End Function

Set objShell = WScript.CreateObject("WScript.Shell")
Set objFso = WScript.CreateObject("Scripting.FileSystemObject")
If isRunning("mysqld.exe")
   objShell.Run("c:\xampp\apache\bin\pv.exe -f -k mysqld.exe -q")
   Set computerName = CreateObject("WScript.Network").ComputerName
   objFso.DeleteFile("c:\xampp\mysql\data\" & computerName & ".pid")
End If
If isRunning("httpd.exe")
   objShell.Run("c:\xampp\apache\bin\pv.exe -f -k httpd.exe -q")
   objFso.DeleteFile("c:\xampp\apache\logs\httpd.pid")
End If

Or just open the XAMPP Control Panel and click Stop.

Now I remember why I never bothered scripting it. These are rather simple tasks which I could perform with Xampp Control Panel manually just as well ;-)


Good luck !!!
stamboom.BertKoor.nl runs on webtrees v1.7.9
Last Edit: 1 year 5 months ago by bertkoor.
The administrator has disabled public write access.

webtrees and VBS 1 year 5 months ago #4

  • dhwtrees
  • dhwtrees's Avatar
  • Offline
  • New
  • Posts: 23
Thanks Bert, much appreciated.
Some small changes and this runs without the Control Panel:
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )

Function isNotRunning(processName)
Set colProcessList = GetObject("Winmgmts:").ExecQuery ("Select * from Win32_Process where Name='" & processName & "'")
'isNotRunning = (colProcessList.count == 0)

If colProcessList.count = 0 then isNotRunning = True

End Function

'Set objShell = WScript.CreateObject("WScript.Shell")
If isNotRunning("httpd.exe") then objShell.Run("c:\xampp\apache\bin\httpd.exe")

If isNotRunning("mysqld.exe") then objShell.Run("c:\xampp\mysql\bin\mysqld --defaults-file=mysql\bin\my.ini --standalone --console")

objShell.Run("http://localhost/webtrees/login.php")

Set objShell = Nothing
Set colProcessList = Nothing

For my purpose the same problem - multiple tabs when the script is run (a wscript shortcut on the taskbar for a single click to start apache+mysql+php). Nothing on the internet that sensibly points to a means of checking if a browser tab i.e. webtrees tab, is already open.

Dave

Edit 15 December
Ran the above from a cold start - fails.
Last Edit: 1 year 5 months ago by dhwtrees. Reason: script fails to run
The administrator has disabled public write access.

webtrees and VBS 1 year 5 months ago #5

  • bertkoor
  • bertkoor's Avatar
  • Offline
  • Gold
  • Greetings from Utrecht, Holland
  • Posts: 1545
I've been going through your changes, looks good! It's a bit weird to me that in vbscript sometimes you can get away with just Set-ting a variable without first Dim-ming it. Probably only when it's in a local scope. Too bad also that the assignment of isNotRunning didn't work as I expected by letting it evaluate the comparison to a boolean result, but you need a fully written if-then. Guess those are the subtle differences between vbscript and PowerShell (and most other modern languages)

dhwtrees wrote:
Set objShell = Nothing

Good thing you do tidy up, but I don't think that's actually required. Once the script exits, all variables & contents should be discarded anyway. Or is this script not started from the desktop, but from within MsWord, Excel or Access?

dhwtrees wrote:
multiple tabs when the script is run


It might be a matter of expectations, but my first thought is this is a pilot's error. You would remember you had already opened a browser tab with webtrees. So personally I wouldn't expect the script to look that up. But if you really want to, I guess it could be done. BUT: with the opened tab you're already logged in! So why let it navigate to the login page again? Shouldn't you just let it navigate to index.php and you then click the Login menu item when needed?

Anyway, here's a related StackOverflow item: stackoverflow.com/questions/16523271/acc...ie-tabs-once-created
Especially take a look at the answer provided by Winand, which actually shows how to retrieve information about the opened tabs in IE.

Can't help you any futher than that alas... Firstly because I don't use a Windows OS at the moment so I cannot even test the code snippets, and secondly because I think the time you save by executing the script is in no relation with the time you spend writing it. But each to their own...
stamboom.BertKoor.nl runs on webtrees v1.7.9
Last Edit: 1 year 5 months ago by bertkoor.
The administrator has disabled public write access.

webtrees and VBS 1 year 5 months ago #6

  • dhwtrees
  • dhwtrees's Avatar
  • Offline
  • New
  • Posts: 23
I approached this as a quick and dirty fix then moved on and just used my original script, it worked. Definitely needs more attention to sort it out. Debugging is a pain because a restart is required each time a test script is run. That caught me out from a cold start this morning when httpd etc raised errors which were not there from a warm start. The multiple tabs are not really an issue and I have just been closing them, should I forget and re-run the script.

Dave
The administrator has disabled public write access.

webtrees and VBS 1 year 4 months ago #7

  • dhwtrees
  • dhwtrees's Avatar
  • Offline
  • New
  • Posts: 23
This is a silent install - no XAMPP control panel. It includes pieces of Bert's code. 1st run about 3 secs then with Apache and MySQL running as background processes an immediate webtrees start (browser = Firefox Quantum):

Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )

'If isNotRunning("xampp-control.exe") then objShell.Run("C:/xampp/xampp-control.exe")

If isNotRunning("httpd.exe") then objShell.Run chr(34) & "C:\xampp\apache\bin\httpd.exe" & Chr(34), 0

If isNotRunning("mysqld.exe") then objShell.Run """C:\xampp\mysql\bin\mysqld.exe"" --defaults-file=C:\xampp\mysql\bin\my.ini --standalone --console", 0

objShell.Run("http://localhost/webtrees/login.php")
Set objShell = Nothing

Function isNotRunning(processName)
Set colProcessList = GetObject("Winmgmts:").ExecQuery ("Select * from Win32_Process where Name='" & processName & "'")
If colProcessList.count = 0 then isNotRunning = True
End Function
The administrator has disabled public write access.
Powered by Kunena Forum