INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: is is possible to delay the connection of a library to a server?  (Read 11846 times)

JustinChase

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3276
  • Getting older every day
is is possible to delay the connection of a library to a server?
« on: February 01, 2016, 12:03:06 pm »

I have 2 Virtual Machines running on my unRAID server, one HTPC and one bedroom PC.  The bedroom PC connects to the HTPC library to keep it in sync with the 'main library'.  This works good.  I have both machines set to launch MC upon windows startup.  I want to set both Virtual Machines to automatically startup when the server reboots (which isn't that often).  But, if the bedroom PC happens to start and try to connect before the HTPC is up and running, it gives a warning that it can't connect to the HTPC library, and lets me select what i want to happen.  I don't have a mouse or keyboard assigned to this VM, so I can't easily select an option, so the system kind of hangs until I RDC in and 'fix' it.

So, I'm wondering if there is a way to force it to continue checking for the library, or delay it's startup by a minute or so, to be sure the other VM is running first?
Logged
pretend this is something funny

mdav

  • Junior Woodchuck
  • **
  • Posts: 62
Logged

JustinChase

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3276
  • Getting older every day
Re: is is possible to delay the connection of a library to a server?
« Reply #2 on: February 01, 2016, 12:32:36 pm »

Yeah, kinda like that, but I don't want to mess about with batch files, and registry hacks, especially with that solution being version dependent, meaning I'll have to re-learn the solution with every new version, which are spaced out just long enough for me to forget these kinds of one-off solutions :)
Logged
pretend this is something funny

mwillems

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 5242
  • "Linux Merit Badge" Recipient
Re: is is possible to delay the connection of a library to a server?
« Reply #3 on: February 01, 2016, 12:34:14 pm »

I have 2 Virtual Machines running on my unRAID server, one HTPC and one bedroom PC.  The bedroom PC connects to the HTPC library to keep it in sync with the 'main library'.  This works good.  I have both machines set to launch MC upon windows startup.  I want to set both Virtual Machines to automatically startup when the server reboots (which isn't that often).  But, if the bedroom PC happens to start and try to connect before the HTPC is up and running, it gives a warning that it can't connect to the HTPC library, and lets me select what i want to happen.  I don't have a mouse or keyboard assigned to this VM, so I can't easily select an option, so the system kind of hangs until I RDC in and 'fix' it.

So, I'm wondering if there is a way to force it to continue checking for the library, or delay it's startup by a minute or so, to be sure the other VM is running first?

It might be easier to add the delay outside the VMS (i.e. add the delay to whatever script is starting the VMs on the unraid server).
Just start the first VM, use whatever command your scripting language uses for delay (bash uses "sleep") for a minute or two, and then start the second VM.  I've never used UnRAID, but I'm assuming it's Linux or BSD based so it should be easily scriptable.
Logged

JustinChase

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3276
  • Getting older every day
Re: is is possible to delay the connection of a library to a server?
« Reply #4 on: February 01, 2016, 12:39:49 pm »

It might be easier to add the delay outside the VMS (i.e. add the delay to whatever script is starting the VMs on the unraid server).
Just start the first VM, use whatever command your scripting language uses for delay (bash uses "sleep") for a minute or two, and then start the second VM.  I've never used UnRAID, but I'm assuming it's Linux or BSD based so it should be easily scriptable.

That was my first idea, and I asked about it on their forums.  Their VM functionality is now rather 'built-in' to their OS, so there is just a check-box for auto-start, but nothing built in for a delay.  I'm afraid if I try to dig into their system to force a delay I could either create problems, or have it overwritten with a version update.

In the end, I'm not restarting the server very often, so this isn't a very important thing, but laziness and automation are close to my heart, so I felt it worth pursuing.

I may end up trying to use windows scheduling to have it delay the autostart of MC as a windows service (based on an unRAID forum user suggestion), but wanted to see if a simpler solution (like MC just re-trying to connect to a missing library for a couple of minutes) might present itself.
Logged
pretend this is something funny

rudyrednose

  • Regular Member
  • Galactic Citizen
  • ****
  • Posts: 344
  • nothing more to say...
Re: is is possible to delay the connection of a library to a server?
« Reply #5 on: February 01, 2016, 01:14:38 pm »

Not directly the same thing, but:
- I answered a related question (headless client MC trying to connect to MC server before its own networking stack was stable) suggesting using Windows Scheduler and "wait on network connection event".   See http://yabb.jriver.com/interact/index.php?topic=91700.msg631144#msg631144
- you mention not wanting to do batch files nor registry hacks, but what about on the HTPC and the bedroom PC (in a startup batch file) ping the VM running MC server and only launch MC when success + some delay for MC server to start ?
- even better (I am not familiar with it though) from the client use JRiver's MCWS to check when MC server is alive THEN launch your MC client.

The latter should be simple and not version dependant for anything...

Cheers.
Logged

JustinChase

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3276
  • Getting older every day
Re: is is possible to delay the connection of a library to a server?
« Reply #6 on: February 01, 2016, 02:19:01 pm »

Not directly the same thing, but:
- I answered a related question (headless client MC trying to connect to MC server before its own networking stack was stable) suggesting using Windows Scheduler and "wait on network connection event".   See http://yabb.jriver.com/interact/index.php?topic=91700.msg631144#msg631144
- you mention not wanting to do batch files nor registry hacks, but what about on the HTPC and the bedroom PC (in a startup batch file) ping the VM running MC server and only launch MC when success + some delay for MC server to start ?
- even better (I am not familiar with it though) from the client use JRiver's MCWS to check when MC server is alive THEN launch your MC client.

The latter should be simple and not version dependant for anything...

Cheers.


I also looked into setting the default windows version delay selection option, but I'm not sure it even shows a choice if there is only 1 version installed, so I don't think setting a delay there is going to work either.
I don't necessarily want to wait for network connection, as they should both have it at similar times, so it's not necessarily a good indicator
I just looked into scheduling an event, but that's going to be version dependent, since I have to select the .exe, which changes location based on version.
I'm interested in the 3rd option you mention MCWS to check when server is alive, but I don't have any idea how to do that yet.  I'm going to hit the wiki and look for help, but that seems like the best option so far.

Thanks for the help.
Logged
pretend this is something funny

JustinChase

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3276
  • Getting older every day
Re: is is possible to delay the connection of a library to a server?
« Reply #7 on: February 01, 2016, 02:30:24 pm »

sadly, documentation of MCWS isn't easy to come by.  First, I can't even connect to the MCWS server from a remote machine to see the API.  I've tried the IP of the server machine, with and without the port included, from firefox and chrome; I could never connect.

Maybe somebody that knows how to use this can give me a simple 'do this' instruction for connecting the remote computer with a delay.  I don't want to spend hours fighting just to connect, then more hours on trial and error.  Lazy?  yes, but I don't restart the server very often, so this is a 'nice to have' not a super important need.
Logged
pretend this is something funny

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: is is possible to delay the connection of a library to a server?
« Reply #8 on: February 01, 2016, 02:32:44 pm »

MCWS is self-documenting. What do you mean?
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: is is possible to delay the connection of a library to a server?
« Reply #9 on: February 01, 2016, 02:34:52 pm »

If you want a MC Command Line launcher that isn't version specific (for scripts and whatnot) you can use MCcl.exe from my MCUtilities pack:
http://blog.glynor.com/mcutilities/
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

JustinChase

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3276
  • Getting older every day
Re: is is possible to delay the connection of a library to a server?
« Reply #10 on: February 01, 2016, 02:48:12 pm »

MCWS is self-documenting. What do you mean?

I mean, since I can't seem to connect to it, I can't get any documentation :(

I've tried from a remote machine (my laptop), and from within an RDC connection on the VM running the server, and no combination of localhost, media (the name of my server on the network), the server IP, or the VM IP, with or without various ports (145 - the port forwarded to that machine in my router, 52199 and none) could connect to MCWS.

I'm sure I'm not doing it right, but since there is no documentation until you connect, I gave up.

I see your post below with your tools, but after reading, it seems I have to run an update after any new version; and while this is clearly simple, it involves me remembering to do it 12-18 months after setting it up; which is unlikely.  I would rather find some solution which I can setup now, and not have to deal with ever again (short of nuke/pave the OS).

I know, I'm being picky, but I know myself, and I'll pull my hair out for hours trying to remember why it's not working next year, so I'd rather have no solution than face the hours of frustration of not remembering later :(
Logged
pretend this is something funny

CountryBumkin

  • Citizen of the Universe
  • *****
  • Posts: 3352
Re: is is possible to delay the connection of a library to a server?
« Reply #11 on: February 01, 2016, 03:12:02 pm »

So ideally, if the developers could add more time to the server connection attempt before the dialog window comes up, the problem would take care of itself. How long does it take for your server connection to be made available?
Logged

JustinChase

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3276
  • Getting older every day
Re: is is possible to delay the connection of a library to a server?
« Reply #12 on: February 01, 2016, 03:22:58 pm »

Ideally, I could select an option like "attempt to reconnect x times" before the pick a different library box was displayed. 

Short of that, I suspect both machines should be up and running within about 30 seconds of each other, but I suppose if the server had a windows update it needed to apply upon startup, but the remote machine didn't have such an update, it could be a few minutes before the server would be available.
Logged
pretend this is something funny

CountryBumkin

  • Citizen of the Universe
  • *****
  • Posts: 3352
Re: is is possible to delay the connection of a library to a server?
« Reply #13 on: February 01, 2016, 03:31:11 pm »

Ideally, I could select an option like "attempt to reconnect x times" before the pick a different library box was displayed. 

If you can get the attention of one of the developers,  ::) maybe this would not be too hard for them to do. Even if not a selectable option, just add more connection attempts before going to fail. For the typical system (that connects right away) this is not even going to be noticed.
In my system I would rather have the Client keep trying to connect to Server's library - unless I manually stop it.
Good luck
Logged

JustinChase

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3276
  • Getting older every day
Re: is is possible to delay the connection of a library to a server?
« Reply #14 on: February 01, 2016, 03:34:36 pm »

Thanks, I agree, for most this change would go unnoticed.  Hopefully the fact this has been near the top of the boards all day has attracted their attention, and that they don't dislike me enough to consider the change :)
Logged
pretend this is something funny

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: is is possible to delay the connection of a library to a server?
« Reply #15 on: February 01, 2016, 05:23:01 pm »

I mean, since I can't seem to connect to it, I can't get any documentation :(

I've tried from a remote machine (my laptop), and from within an RDC connection on the VM running the server, and no combination of localhost, media (the name of my server on the network), the server IP, or the VM IP, with or without various ports (145 - the port forwarded to that machine in my router, 52199 and none) could connect to MCWS.

Well, then... You wouldn't be able to use it anyway.  ;) ;D

There isn't much to it. On the server itself, use this in a web browser:
http://localhost:52199/MCWS/v1/

If you altered the default port, then replace 52199 in the URL above with the Port specified in Tools > Options > Media Network > Advanced > TCP Port. This should be 52199 by default and if you do it pointed at localhost, then port forwarding and all of that doesn't matter.

If that doesn't work, then something on the server itself is blocking the connection. That's why trying that first is always the best test.

Then, to test the connection from a different device, you'll want to use that same URL in a browser, only replacing the localhost thing with the IP address of the server, from any device from which you want to send the commands. That's all covered here:
http://wiki.jriver.com/index.php/Web_Service_Interface
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

JustinChase

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3276
  • Getting older every day
Re: is is possible to delay the connection of a library to a server?
« Reply #16 on: February 01, 2016, 05:50:40 pm »

Okay, apparently I didn't try the winning combination 192.168.20.145:145 which is the IP of the server, and the port I use for Gizmo to that machine.  (I have each machine use a different port so I can connect to all my machines independently from one another)  I actually thought I tried that, but whatever, http://192.168.20.145:145/MCWS/v1/ connected me to the server, so now I see the documentation.  I'll look thru it and see if I can now figure out how to use that to only connect the remote computer to this library server if it's running.

fingers crossed :)

Thanks for pushing me to a solution
Logged
pretend this is something funny

JustinChase

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3276
  • Getting older every day
Re: is is possible to delay the connection of a library to a server?
« Reply #17 on: February 01, 2016, 05:57:57 pm »

Okay, so it seems like this would be what I want...

      Connect
         Connects to a remote library.
         Parameters:
            URL: A URL for connecting to a library server. (default: )
         Response:
         Examples:
            Click here


If I "Click here" I get...

This XML file does not appear to have any style information associated with it. The document tree is shown below.
      <Response Status="Failure"/>

Not only does that seem like it wouldn't work, even it it said "Success", I would have no idea how to use that to have the secondary computer try to connect to the server.  There is no syntax I can see to use, no actual example to base my setup on, nothing useful really.  I'm guessing a programmer might understand what to do with that, but I'm lost as to what to do with the documentation it's presenting me.
Logged
pretend this is something funny

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: is is possible to delay the connection of a library to a server?
« Reply #18 on: February 01, 2016, 06:03:59 pm »

Okay, so it seems like this would be what I want...

      Connect

I'm actually not 100% positive what Connect does, though I suspect it only works with a native MCWS client (and not a web browser), like MC itself.

If you just want to test if the server is alive, then the best one to use is Alive:
http://localhost:52199/MCWS/v1/Alive

I'm not sure what you're trying to accomplish. I was mostly just commenting that MCWS isn't well documented. It is pretty well documented, for a REST based interface.

If you need to delay launching of things at boot time in Windows, there is a whole Task Scheduler UI that lets you do that. So, I'm a bit confused about the basic premise of the question...
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

JustinChase

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3276
  • Getting older every day
Re: is is possible to delay the connection of a library to a server?
« Reply #19 on: February 01, 2016, 06:08:11 pm »

Thanks Glynor, I appreciate the help.  All I'm trying to do it make a client wait until a server is online before connecting.  Whether using MCWS or some other method.  I just don't want the client trying to connect before the server is available, then getting the box asking me what to do, as I don't have a keyboard or mouse connected to the client machine, do I can't easily act on the dialog if it appears.
Logged
pretend this is something funny

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: is is possible to delay the connection of a library to a server?
« Reply #20 on: February 01, 2016, 07:33:20 pm »

This would be a reasonably simple scripting task, then. What you'd need to do, is replace your startup "action" on the HTPC instead of directly to MC itself, to a script. That script would be something that:

1. Checks MCWS Alive on the server to see if it is alive.
2. If not, it waits a bit and repeats #1.
3. When #2 passes, then it launches MC.

I could help you write this, though I don't know if it'd be tonight.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

JustinChase

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3276
  • Getting older every day
Re: Re: is is possible to delay the connection of a library to a server?
« Reply #21 on: February 01, 2016, 08:17:16 pm »

This would be a reasonably simple scripting task, then. What you'd need to do, is replace your startup "action" on the HTPC instead of directly to MC itself, to a script. That script would be something that:

1. Checks MCWS Alive on the server to see if it is alive.
2. If not, it waits a bit and repeats #1.
3. When #2 passes, then it launches MC.

I could help you write this, though I don't know if it'd be tonight.
That seems like a good solution.  I'll try to figure that out and report back.

Thanks again for the help!
Logged
pretend this is something funny

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: is is possible to delay the connection of a library to a server?
« Reply #22 on: February 01, 2016, 11:43:31 pm »

Here you go:
http://glynor.com/files/MCUtilities/MC-Wait_for_Alive_to_Launch-1030.zip
EDIT: See below for usage updates for current version.

TO USE:

1. Download and extract the ZIP file, which will give you a VB script file (vbs).
2. Open the file in a text editor (notepad.exe is fine) and edit the stuff in the User Defined Variables section of the script.
3. Run the script instead of launching MC directly. If asked what to launch it with, you want to choose the Microsoft Windows Based Script Host (wscript.exe) application.

The stuff you have to modify is this part, and should be pretty straightforward:
Code: [Select]
' ************************************************************************************************************
' USER DEFINED VARIABLES
' ************************************************************************************************************
' You need to modify the values below to point to the server you want to use with this script.

' The Server Address
const strServerAddress = "SERVERADDRESS:PORT"
' EXAMPLES
' const strServerAddress = "myserver.mynetwork.com:52199"
' const strServerAddress = "192.168.3.200:52199"

' Authentication
const enableAuthentication = 1 ' Set to zero to disable authentication support
const strUsername = "USERNAME"
const strPassword = "PASSWORD"

' MC Version for launching, or COM to use the most-recently launched version of MC
const launcherType = "cl"
' If you want to use MCcl.exe (part of MCUtilities) specify "cl".
' More info on MCcl.exe: http://blog.glynor.com/mccl/
' If you want to use a specific one of the standard MC Command Line Launchers, just specify the major version
' If you want to use the COM launcher (which loads the most-recently-used version of MC) specify "com"
' EXAMPLES
' const launcherType = 21 ' This will always launch MC21
' const launcherType = "cl" ' This will use MCcl.exe to load the version you saved using it.
' const launcherType = "COM" ' This will use COM to launch the most-recently-launched version.

' If you need to change the default MC command line launch command, do it here.
const launchCommand = "/Start"

' If you want a longer timeout before it gives up, increase this. Each loop waits approximately 20 seconds before trying again.
const maxLoops = 6

' If you want it to launch MC anyway when it gives up, then set this to 1.
const launchEvenWhenFailed = 0

' END USER DEFINED VARIABLES
' ************************************************************************************************************
' ************************************************************************************************************

By default, it'll wait around 2 minutes before it gives up. If it gives up, it'll show you an error.

A few things worth noting:

* This requires Media Network to be enabled on the SERVER (somewhat obviously) and, because I was lazy, requires it to have a Username and Password set.
* If you run yours without authentication for some reason, it should be possible to modify it, but I was too lazy to look that part up and add in checking code.
* You DO have to edit the script to specify the version of MC that you are using. Meaning, it doesn't solve this:

it involves me remembering to do it 12-18 months after setting it up; which is unlikely.  I would rather find some solution which I can setup now, and not have to deal with ever again (short of nuke/pave the OS).

I know, I'm being picky, but I know myself, and I'll pull my hair out for hours trying to remember why it's not working next year, so I'd rather have no solution than face the hours of frustration of not remembering later :(

There's not a clean way to solve that. MC doesn't provide a non-version-specific launcher. I could, I suppose, code this to launch MC via COM (which wouldn't require the launcher) but that could have weird side effects when you are "between versions" and that seems to be a tough pill to swallow. Plus, it is a pain to do and I'm doing this for free (and already spent like 4 hours on it).

The issue is, if I do it via COM, then it'll launch whichever version of MC was last-used on the system. (Actually, technically, it would launch whichever version has the COM component registered, which is what it is doing that causes you to get the UAC prompt when you switch back and forth between versions of MC). This could certainly work, but it might make the script do "unexpected things" to you when the next big version of MC comes out.

Seems like it is better for you to write yourself a note.  ;) ;D

EDIT: Immediately after posting this, I thought of something else. I bumped it to 1.0.1 and added a little feature to let you more easily change the mcXX.exe command it sends when it succeeds (defaults to /start) in the User Defined Variables section. The original is gone now never to be spoken of again. If you happened to grab it in the 10 minutes I had it up, then delete it and get the new one instead.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: is is possible to delay the connection of a library to a server?
« Reply #23 on: February 02, 2016, 12:18:25 am »

Also worth noting a couple things about how to launch this and make a shortcut for it (that doesn't look ugly).

If you are running it from the Windows Task Scheduler:

* You need to specify the script engine. This script requires wscript.exe (because it uses message boxes for errors), and so you need to use this as the command line you set up:
Code: [Select]
wscript.exe MC-Wait_for_Alive_to_Launch.vbs
The script host has some other options if you want to look at them:
https://technet.microsoft.com/en-us/library/ee156587.aspx

* You also need to specify a valid working directory or the Task Scheduler will eat it for some dumb reason. You can't leave it blank.

* You can't run it before you are logged in, because wscript.exe doesn't work, but neither does MC, so that would be pointless.

If you want to run it from a BAT file for some reason:

Same thing. Specify wscript.exe at the command line:
https://technet.microsoft.com/en-us/library/ee156587.aspx

If you want to make it have an icon that looks like the MC icon:

Easy:

1. Save the script somewhere you won't lose it and where it isn't in the way, and do your edits on it there.
2. Make a shortcut to it.
3. Right-click on the Shortcut and choose Properties. On the Shortcut tab, you can click Change Icon, and browse for the Media Center application to choose it's icon.
4. Copy this Shortcut to wherever you want to launch it. To put it in the Start Menu, copy it somewhere here:
C:\ProgramData\Microsoft\Windows\Start Menu\Programs
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

JustinChase

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3276
  • Getting older every day
Re: is is possible to delay the connection of a library to a server?
« Reply #24 on: February 02, 2016, 04:11:21 pm »

Here you go:
http://glynor.com/files/MCUtilities/MC-Wait_for_Alive_to_Launch-1010.zip

WOW!!  Thank you so much for taking so much of your valuable time to do this for me.  I'll work in implementing it soon and let you know how I get on.

Seriously, much appreciated!
Logged
pretend this is something funny

muzicman0

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1239
Re: is is possible to delay the connection of a library to a server?
« Reply #25 on: February 02, 2016, 05:37:38 pm »

Admittedly, I ripped this code from a webpage, and adapted it, however, I successful launched MC21.exe without specifying the file version number.  This code should only be run if 1 version of MC is installed, not sure what will happen if there are more than one.  Also, there is a small risk that there could be another .EXE that begins with MC and has numbers, but I think that risk is small.

Basically the vbs script will scan the System32 folder starting at MC1.exe and then increment 1 number at a time and if it finds a match, it will launch the .exe.

I am thinking this could be incorporated into Glynors scripts above so that you don't have to have MC21.exe hard coded.

Here is the code:

Code: [Select]
Const csCDRoot = "C:\Windows\System32\"

Dim oFSO : Set oFSO = CreateObject( "Scripting.FileSystemObject" )
Dim oWSH : Set oWSH = CreateObject( "WScript.Shell" )
Dim oRE : Set oRE = New RegExp
oRE.IgnoreCase = True
oRE.Pattern = "^MC\d+\.exe$"
ExecCDFiles oFSO.GetFolder( csCDRoot ), oFSO, oRE, oWSH


Sub ExecCDFiles( oFldr, oFSO, oRE, oWSH )
Dim oItem
For Each oItem In oFldr.Files
If oRE.Test( oItem.Name ) Then
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run oItem.path
End If
Next

End Sub

Full disclosure:  While I am decent at vbs script, I don't follow 100% everything this script does...It does work though, and I have a basic understanding of what it is doing.
Logged

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4277
Re:
« Reply #26 on: February 02, 2016, 05:59:31 pm »

It appears to be testing each file in windows/system32 to see if the name is MC then 1 or more digits then .exe, if match then execute file. I don't see where the "start at 1 and increment" bit comes from, it could be your interpretation of a file list that has been lexically sorted perhaps?

If there were multiple MC exes then if would execute the first one, if WshShell.Run doesn't block then it would run them all - https://msdn.microsoft.com/en-us/library/d5fk67ky(v=vs.84).aspx indicates the default is to run the process asynchronously so you would run them all.
Logged

muzicman0

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1239
Re: is is possible to delay the connection of a library to a server?
« Reply #27 on: February 02, 2016, 06:09:28 pm »

Did some basic testing, and MCa.exe or MCbb.exe does not work, so it does appear to have to be numbers.  I think the escaped d+ is saying to match all instances of MC#.exe where # is a number.  My guess is that you could add an exit sub after the run command and then at least it would only run the first instance.
Logged

muzicman0

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1239
Re: is is possible to delay the connection of a library to a server?
« Reply #28 on: February 02, 2016, 06:12:44 pm »

yep...found this:

\d+ will match any digit one or more times, and is the equivalent to [0-9]+

so it will require it to be MC and then a number.
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: is is possible to delay the connection of a library to a server?
« Reply #29 on: February 02, 2016, 06:32:26 pm »

I am thinking this could be incorporated into Glynors scripts above so that you don't have to have MC21.exe hard coded.

Oh dear lord don't do it that way. Like a savage banging on sticks with rocks!  ;D

If nothing else, it'd be slow to parse the filesystem! And what about if you have two (or three or four) different major versions installed (for testing or because you forgot to remove them later)?

If you really want to implement it via COM (which is the right way to do it), I made it easy in my script to change it.  To launch MC it runs a subroutine called LaunchMC(). You'd basically just need to alter this one sub in the script to do what the VB example code for initialization on the Automation article on the Wiki does:

Code: [Select]
On Error Resume Next
Set myobj = GetObject(, "MediaJukebox Application")

If Err.Number = 429 Then
    'Then, create a new object
    Set myobj = CreateObject("MediaJukebox Application")

That might need some tweaks to work in VB Script vs. the full .NET Runtime, but I'm pretty sure I have code in a vbscript somewhere that does this (better than the sample code).

If you are determined, I could pull it out.  The issue is that, as I mentioned above, this will then basically always launch whichever version of MC you "last used". With long experience, this has been problematic for me in the past for some purposes, and it is sometimes better to specify a version manually. That's why the launcher from JRiver is the way it is, because it lets you be specific in a script (which might do things behind your back when you aren't sitting there at the computer, and do them fast and in a way that is destructive). What about when MC22 comes out and you install the first few betas to check them out, but they're fragile and you don't want to run it full time with your "real" Library? I always test the early betas for at least a month or two before I let them loose on my real stuff...

It would be better, IMHO, to just switch the script to use my MCcl.exe program.  What that basically does, by the way, is checks which version is registered with COM when you run it with the --update switch, and then saves that on file to disk and uses it every time until you use the --update switch again.

The script I wrote above can be used with MCcl.exe just fine. Just (1) make sure MCcl.exe is in your system's default search path, and (2) change the intVersion constant in the script to:
Code: [Select]
const intVersion = "cl"
That way, when you decide to switch to MC23, you just run one time: MCcl.exe --update
Done.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

muzicman0

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1239
Re: is is possible to delay the connection of a library to a server?
« Reply #30 on: February 02, 2016, 06:51:28 pm »

I agree it is a bit hacky, however, it works, and while it may be slow, it took less than 1 second to do it's thing.

I agree though on having more than one version installed.  That would be a problem.
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: is is possible to delay the connection of a library to a server?
« Reply #31 on: February 02, 2016, 09:32:23 pm »

Okay, you savages.  ;D

1.0.2 (2016-02-02)
http://glynor.com/files/MCUtilities/MC-Wait_for_Alive_to_Launch-1020.zip

1. Added a mode that launches using COM instead of the specified MC Command Line Launcher.
2. Made the Server checking into a function call
3. Made the default launcher MCcl.exe

This changes the behavior of the launcherVersion constant (which used to be just called intVersion) to this:
Code: [Select]
' MC Version for launching, or COM to use the most-recently launched version of MC
const launcherVersion = "cl"
' If you want to use MCcl.exe (part of MCUtilities) specify "cl".
' More info on MCcl.exe: http://blog.glynor.com/mccl/
' If you want to use a specific one of the standard MC Command Line Launchers, just specify the major version
' If you want to use the COM launcher (which loads the most-recently-used version of MC) specify "com"
' EXAMPLES
' const launcherVersion = 21 ' This will always launch MC21
' const launcherVersion = "cl" ' This will use MCcl.exe to load the version you saved using it.
' const launcherVersion = "COM" ' This will use COM to launch the most-recently-launched version.

It now defaults to using MCcl.exe because that's the best way IMHO, and that's how I'd use it (if I were ever going to use it). However, if you want to use the most-recently-used version of MC automatically, then you can set it to "COM" and it'll do it that way.

One side effect of using COM mode, that is probably not a big deal, but worth mentioning...

If MC isn't running at all on the system when you run this script, it has to actually launch MC, to query which version it is, before it can send the command specified in the launchCommand constant. It, of course, doesn't do this until after it has verified there is a server to connect to, so no big deal. But, this means that MC itself will load a split second before the launchCommand is actually sent.

If you're just leaving the launchCommand set to the "default mode" (/Start) then it won't matter at all, and there will be no difference.

However, if you're trying to go directly to some particular mode of MC (perhaps Theater View) by specifying a different command line option, then it'll load MC in it's "regular mode" for a split-second, get the version number, and then send the command. This could mean you'll see the Standard View UI for an instant before it sends the full command line specified.

If this happens on your system and it takes a while and it really ticks you off, then either:
* Change your Startup mode in MC (Tools > Options > Startup > Startup Interface > Mode), or...
* Don't use the COM version and use MCcl.exe or a manually specified version instead.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: is is possible to delay the connection of a library to a server?
« Reply #32 on: February 02, 2016, 09:42:36 pm »

Worth noting that you don't have to use this script to launch MC. That's why I added in that launchCommand constant.

If you have some need to run any mcXX.exe command (a MC Core automation command, or any of the other command line functions) but you only want to do it when a specific server is online and responding, you could use this.

If you want to run something other than /Start just change the launchCommand item.
If you don't want it to try over and over, just set the maxLoops to 1.

So, pretty handy for the toolkit in the end, and I'll keep it. And I'll include it the next time I build MCUtilities.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: is is possible to delay the connection of a library to a server?
« Reply #33 on: February 02, 2016, 09:48:54 pm »

Oh, crud. I forgot to wrap one of my new notices in a if Verbosity statement. Hold on...
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: is is possible to delay the connection of a library to a server?
« Reply #34 on: February 02, 2016, 10:09:16 pm »

1.0.3 (2016-02-02)
http://glynor.com/files/MCUtilities/MC-Wait_for_Alive_to_Launch-1030.zip

1. Fixed: It showed a diagnostic message when activating COM mode even if Verbosity was off.
2. Added: enableAuthentication constant allows you to disable authentication for servers that have this off.
3. Fixed: launcherType constant was named the wrong thing

I fixed two bugs I didn't catch in the previous version (which didn't work and I pulled after only a short bit), and I added something.  ;)

1. I have diagnostic messages in the script you can see if you pass the script /verbosity:on. I put one of these in there when it activated COM mode, and forgot to only show it when verbosity was turned on.

2. I also, because why not and when I looked it up it was easy, added the ability to disable authentication if you don't need that.

3. I also messed up when I copy-pasted the User Defined Variables section. The constant you define to specify which version of MC to run is called launcherType, not launcherVersion (which is used internally when the COM mode is used). Sorry, I had different User Defined Variables in my "testing" version of the script (which has my server's address, username, password, etc in it) and I messed up copypasting them before releasing it.

So, the new User Defined Variables section is:
Code: [Select]
' ************************************************************************************************************
' USER DEFINED VARIABLES
' ************************************************************************************************************
' You need to modify the values below to point to the server you want to use with this script.

' The Server Address
const strServerAddress = "SERVERADDRESS:PORT"
' EXAMPLES
' const strServerAddress = "myserver.mynetwork.com:52199"
' const strServerAddress = "192.168.3.200:52199"

' Authentication
const enableAuthentication = 1 ' Set to zero to disable authentication support
const strUsername = "USERNAME"
const strPassword = "PASSWORD"

' MC Version for launching, or COM to use the most-recently launched version of MC
const launcherType = "cl"
' If you want to use MCcl.exe (part of MCUtilities) specify "cl".
' More info on MCcl.exe: http://blog.glynor.com/mccl/
' If you want to use a specific one of the standard MC Command Line Launchers, just specify the major version
' If you want to use the COM launcher (which loads the most-recently-used version of MC) specify "com"
' EXAMPLES
' const launcherType = 21 ' This will always launch MC21
' const launcherType = "cl" ' This will use MCcl.exe to load the version you saved using it.
' const launcherType = "COM" ' This will use COM to launch the most-recently-launched version.

' If you need to change the default MC command line launch command, do it here.
const launchCommand = "/Start"

' If you want a longer timeout before it gives up, increase this. Each loop waits approximately 20 seconds before trying again.
const maxLoops = 6

' If you want it to launch MC anyway when it gives up, then set this to 1.
const launchEvenWhenFailed = 0

' END USER DEFINED VARIABLES
' ************************************************************************************************************
' ************************************************************************************************************
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/
Pages: [1]   Go Up