How To Run Task If *Not* Connected To Specific Network?

Page 1 of 3 123 LastLast

  1. Posts : 30
    Windows 10
       #1

    How To Run Task If *Not* Connected To Specific Network?


    Hi all,

    I'm looking to run a task that only triggers if *not* connected to a specific network/connected to any network *other* than the one specified (wanted to phrase the question both ways so that it's more likely to help other people out searching for a solution to the same problem!).

    To specify, I use a program that automatically maps all available network drives if connected to my home network ('Network Drive Control'), but I want to trigger a second program to map a single remote drive over the cloud ('Asustor EZ Connect') if connected to any other network.

    How do I go about doing this?
      My Computer


  2. Posts : 16,949
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #2

    Add some initial lines to the batch file that calls the thing you want to decide about.

    Run a Dir command that you know passes on the "the one specified", check the errorlevel and exit if you have not got the expected result.
    - Note that Dir cmds are more reliable than If Exist cmds for this topic

    Code:
    :: test that this is the one specified
    Dir \\SomeComputerThatIsOnTheOneSpecified\SomePathOnIt\SomeFileOnIt.txt
    If %ErrorLevel% EQU 0 GoTo OneSpecifiedIsHere
    GoTo ItIsntHere
    Pause This line is never reached
    
    :OneSpecifiedIsHere
    ::Do whatever I want to if the one specified is detected
    GoTo EndThisBatch
    
    :ItIsntHere
    ::Do whatever I want to if the one specified is not detected
    
    :EndThisBatch

    Denis
      My Computer


  3. Posts : 30
    Windows 10
    Thread Starter
       #3

    Try3 said:
    Add some initial lines to the batch file that calls the thing you want to decide about.

    Run a Dir command that you know passes on the "the one specified", check the errorlevel and exit if you have not got the expected result.
    - Note that Dir cmds are more reliable than If Exist cmds for this topic

    Code:
    :: test that this is the one specified
    Dir \\SomeComputerThatIsOnTheOneSpecified\SomePathOnIt\SomeFileOnIt.txt
    If %ErrorLevel% EQU 0 GoTo OneSpecifiedIsHere
    GoTo ItIsntHere
    Pause This line is never reached
    
    :OneSpecifiedIsHere
    ::Do whatever I want to if the one specified is detected
    GoTo EndThisBatch
    
    :ItIsntHere
    ::Do whatever I want to if the one specified is not detected
    
    :EndThisBatch

    Denis
    Hey there - thanks for your suggestion, but I'm a stuck trying to replace parts with the relevant code.
    Is the idea that I put a file on the mapped drive mapped by 'Network Drive Control' and if the file can't be access then 'Asustor EZ Connect' starts? If so do I run this as a task? 'Network Drive Control' takes around a minute or so to map the drives after logging in so I wouldn't be able to run it at boot, unless we added a delay I guess?
    Thanks again!


    - - - Updated - - -

    Also, how do I use this coding language to open EZ Connect?
    (Sorry, couldn't see a way to edit my last post)
      My Computer


  4. Posts : 16,949
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #4

    The idea is that you think of some file that will be accessible if you are on your home network and run the required programme if that file is found or run a desired programme if that file is not found.

    I have played around with other methods of identifying networks but this method is the only reliable one I have found.

    So, can you think or a file [or can you create a file] on your home network that can act as the marker for your decision?

    Denis
      My Computer


  5. Posts : 30
    Windows 10
    Thread Starter
       #5

    Try3 said:
    The idea is that you think of some file that will be accessible if you are on your home network and run the required programme if that file is found or run a desired programme if that file is not found.

    I have played around with other methods of identifying networks but this method is the only reliable one I have found.

    So, can you think or a file [or can you create a file] on your home network that can act as the marker for your decision?

    Denis
    Ok, so I've got it all set up correctly (thanks again!), but I'm having one issue - the cmd window isn't closing after opening the program

    I'd like to run this whole process as invisibly as possible and so was wondering if we hide the cmd window, and if not, at least have it run minimised?

    Also, is there any way to automatically close the window of the opened program after say 10 seconds? (Scheduled Task/Application Shortcut - How To Close Window : sysadmin)
      My Computer


  6. Posts : 16,949
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #6

    1 It is possible, but unusual, for command windows not to close. Is is possible that your chosen commands have prevented the batch file from completing?
    - Perhaps you have used Start commands and they are holding it up because you? That's unnecessary. All you needed to do was use the same command that is in the shortcut you normally use to run the application.
    - There are many ways to run an application from a batch file.
    - Do this test. Add an additional last line to the batch file to see if it is reached

    Code:
    :: test that this is the one specified
    Dir \\SomeComputerThatIsOnTheOneSpecified\SomePathOnIt\SomeFileOnIt.txt
    If %ErrorLevel% EQU 0 GoTo OneSpecifiedIsHere
    GoTo ItIsntHere
    Pause This line is never reached
    
    :OneSpecifiedIsHere
    ::Do whatever I want to if the one specified is detected
    GoTo EndThisBatch
    
    :ItIsntHere
    ::Do whatever I want to if the one specified is not detected
    
    :EndThisBatch
    Pause at the last line of the batch file
    When you have run that test, let me know the result. You can also post your batch file and I'll have a look at those application commands.

    2 My preferred method of making batch files run inconspicuously is given in Make Task scheduler run a batch file minimised and with a specific icon - TenForums

    3 When the batch file is set up to run minimised and everything is working alright, you can experiment with different ways of minimising the application windows
    - Not all applications will respond to any such attempts
    - I would not expect to be able to start the application in one window state then alter that state later.
    - I suggest that it would be better to focus on starting the applications with minimised windows in the first place.
    - We can discuss this as soon as the current batch file performs adequately.
    - I imagine that I will suggest a solution that is along the same lines as the vbs file shown in the para 2 link but it might be the case that Start commands can achieve the desired result more directly.

    Denis
      My Computer


  7. Posts : 30
    Windows 10
    Thread Starter
       #7

    Try3 said:
    1 It is possible, but unusual, for command windows not to close. Is is possible that your chosen commands have prevented the batch file from completing?
    - Perhaps you have used Start commands and they are holding it up because you? That's unnecessary. All you needed to do was use the same command that is in the shortcut you normally use to run the application.
    - There are many ways to run an application from a batch file.
    - Do this test. Add an additional last line to the batch file to see if it is reached

    Code:
    :: test that this is the one specified
    Dir \\SomeComputerThatIsOnTheOneSpecified\SomePathOnIt\SomeFileOnIt.txt
    If %ErrorLevel% EQU 0 GoTo OneSpecifiedIsHere
    GoTo ItIsntHere
    Pause This line is never reached
    
    :OneSpecifiedIsHere
    ::Do whatever I want to if the one specified is detected
    GoTo EndThisBatch
    
    :ItIsntHere
    ::Do whatever I want to if the one specified is not detected
    
    :EndThisBatch
    Pause at the last line of the batch file
    When you have run that test, let me know the result. You can also post your batch file and I'll have a look at those application commands.

    2 My preferred method of making batch files run inconspicuously is given in Make Task scheduler run a batch file minimised and with a specific icon - TenForums

    3 When the batch file is set up to run minimised and everything is working alright, you can experiment with different ways of minimising the application windows
    - Not all applications will respond to any such attempts
    - I would not expect to be able to start the application in one window state then alter that state later.
    - I suggest that it would be better to focus on starting the applications with minimised windows in the first place.
    - We can discuss this as soon as the current batch file performs adequately.
    - I imagine that I will suggest a solution that is along the same lines as the vbs file shown in the para 2 link but it might be the case that Start commands can achieve the desired result more directly.

    Denis
    1. No luck yet unfortunately mate, now after a long pause 'Press any key to continue . . .' is appearing at the bottom of the cmd window. Here's my batch file at the moment:
    Code:
    :: See if NAS is connected locally
    Dir \\169.254.1.2\Docker\CheckFile2.txt
    If %ErrorLevel% EQU 0 GoTo FileSpecifiedIsHere
    GoTo ItIsntHere
    Pause This line is never reached
    
    
    :FileSpecifiedIsHere
    ::Do whatever I want to if the one specified is detected
    GoTo EndThisBatch
    
    
    :ItIsntHere
    ::Do whatever I want to if the one specified is not detected
    "C:\Program Files (x86)\ASUSTOR\EZ Connect\EasyConnect.exe"
    GoTo EndThisBatch
    
    
    :EndThisBatch
    Pause at the last line of the batch file
    (Tried both with and without the extra 'GoTo EndThisBatch' line.)

    2. Thank you, I will read through this post.

    3. Sure! :)
      My Computer


  8. Posts : 16,949
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #8

    crimsonnight said:
    1. No luck yet unfortunately mate, now after a long pause 'Press any key to continue . . .' is appearing at the bottom of the cmd window. Here's my batch file at the moment:
    Code:
    :: See if NAS is connected locally
    Dir \\169.254.1.2\Docker\CheckFile2.txt
    If %ErrorLevel% EQU 0 GoTo FileSpecifiedIsHere
    GoTo ItIsntHere
    Pause This line is never reached
    :FileSpecifiedIsHere
    ::Do whatever I want to if the one specified is detected
    GoTo EndThisBatch
    :ItIsntHere
    ::Do whatever I want to if the one specified is not detected
    "C:\Program Files (x86)\ASUSTOR\EZ Connect\EasyConnect.exe"
    GoTo EndThisBatch
    :EndThisBatch
    Pause at the last line of the batch file
    1.1 if what you see "after a long pause" is
    Code:
    >Pause at the last line of the batch file
    Press any key to continue . . .
    then that means the end of the batch file is being reached [and should have been reached even before you added that additional last line]. I assume it does close when you press a key.

    1.2 Does "after a long pause" actually mean when that EasyConnect.exe is closed?

    1.3 What effect does changing the EasyConnect.exe command line have?
    Code:
    Start "Starting the application" /MIN "C:\Program Files (x86)\ASUSTOR\EZ Connect\EasyConnect.exe"
    - It should allow the batch file to continue straight through to its end when it runs the application.
    - I've included the first attempt at minimising the application window that I was going to discuss later.

    1.4 Have you also tested the batch file when the home network is not connected? That additional Pause at the last line of the batch file line will also let you see that that is workign through alright.

    Denis
      My Computer


  9. Posts : 30
    Windows 10
    Thread Starter
       #9

    Try3 said:
    1.1 if what you see "after a long pause" is
    Code:
    >Pause at the last line of the batch file
    Press any key to continue . . .
    then that means the end of the batch file is being reached [and should have been reached even before you added that additional last line]. I assume it does close when you press a key.

    1.2 Does "after a long pause" actually mean when that EasyConnect.exe is closed?

    1.3 What affect does changing the EasyConnect.exe command line have?
    Code:
    Start "Starting the application" /MIN "C:\Program Files (x86)\ASUSTOR\EZ Connect\EasyConnect.exe"
    - It should allow the batch file to continue straight through to its end when it runs the application.
    - I've included the first attempt at minimising the application window that I was going to discuss later.

    1.4 Have you also tested the batch file when the home network is not connected? That additional Pause at the last line of the batch file line will also let you see that that is workign through alright.

    Denis
    That extra code fixed it and it is indeed now running minimised - thank you very much :)
    I still have to close the EZ Connect window after the drive's mounted, but still, this is a far more seamless solution than going through the steps manually.
    Do you think it's worth starting a new thread to see if anyone has any ideas in regards to closing the window after a set period of time?

    *EDIT* When I was researching this previously, I did see that there's a way to skip the cmd window showing altogether but I couldn't get it to work (see 2nd answer): windows - Start service from Task Scheduler as minimised - Super User
    The process in the script you've written is so quick to execute though that this is no longer necessary in my instance :)
      My Computer


  10. Posts : 16,949
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #10

    You kept referring to the EZ Connect "window" so I thought that was what you wanted to manipulate. Your last comment makes me think you want to end that application rather than manipulate its window.

    3.1 Please confirm that I now understand you.

    3.2 Are you absolutely certain that you can specify a time period after which you can close the EZ thing? If so, what is it?

    3.3 While the EZ thing is open, please run this command in another comamnd window and look through the list to find the referene to the EZ thing.
    Code:
    tasklist
    - It will probably be EasyConnect.exe

    3.4 Armed with these results, I will suggest a couple of very simple additional lines for the batch file.

    Denis
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 04:29.
Find Us




Windows 10 Forums