Since you say you already have a solution to access a shared folder from your Android phone and confirmed you can access it and delete files, I'll give you the steps to take to setup a batch script on the Windows machine that will simply check for a file there and then take an action based on the conditional IF logic.
- If the file does not exist then it'll disable a network adapter based on interface name.
- If the file does exist then it will exit and not do anything after that.
You will need to use Task Scheduler and use specific settings to ensure the process runs in a hidden manner so it's not visible on the screen when the batch script is executed.
If you want to disable the Network Adapter remotely, connect to the shared folder with your Android phone and simply delete the file. Now every time the batch script is executed it'll disable that NIC.
Prerequisite - Time for some detective work
Get the name of the [interface] Network Adapter you wish to disable by running this in an admin elevated command prompt: netsh interface show interface
. Take note of the "Interface Name" of the network adapter which you wish to disable via command line with the batch script.
I will disable the "Ethernet" named adapter in the examples I provide. You will obviously need to replace this value with the applicable name of the interface in your environment to disable.
![enter image description here](../../I/static/images/200cf20c5e83f15939b60f665b96a45ecbf066c052f774bb82432d22f44f1fc4.png)
![enter image description here](../../I/static/images/981eb7bced0609d77e5ba9e17766aeb8d47da1764d75705339bed8742d756d81.png)
Batch Script to Schedule
Be sure to set the values of the SET Folder=
and SET File=
to equal the valid folder path and file name that the batch file will check whether or not it exists with the conditional IF logic.
Be sure to also set the value of the SET IntName=
to be the value of the Interface Name of the network adapter the batch script will disable.
Example Script (zDisableNic.cmd)
@ECHO ON
SET Folder=C:\SomeFolder
SET File=start.txt
SET IntName=Ethernet
:Routine
SET var=%Folder%\%File%
IF EXIST "%var%" EXIT
netsh int set int "%IntName%" admin=disable
EXIT
You can keep a small batch file in a (or the same) folder if you want to right-click on and select run as administrator to enable the NIC manually quickly as you need to.
Once you create the start.txt
file to ensure the other batch file does not disable the NIC, you then right-click and run as administrator on the EnableNic batch script.
Example Script (zEnableNIC.cmd)
:: Where "Ethernet" is the applicable "Interface Name" value from the result of the `netsh interface show interface` command
SET IntName=Ethernet
netsh int set int "Ethernet" admin=enable
Task Scheduler
From Windows Task Scheduler
on the job Properties
(See below Print Screens)
1. In the General
tab, ensure that the below options are select/checked or unchecked just as shown in the Print Screen "General"
- Uncheck
Run only when user is logged on
- Check
Run whether user is logged on or not
- Check
Run with the highest privileges
2. In the Triggers
tab, ensure that the below options are set just as specified and shown in the Print Screen "Triggers"
3. In the Action
tab, click Edit
, and ensure that the below options are set just as specified and shown in the Print Screen "Action"
the Program/script
value should be the the full path where the batch script is located without a final backslash "\
" but with double quotes around it
the Start in (optional)
value should be set just as shown in the below example—do not put double quote marks around this value though
4. Once you press OK
(maybe twice) you will be prompted for a credential as shown in Print Screen "Credential"
- I created a new user account named
service
on my machine and gave it a strong password, ensured the account was enabled, was set with a password that never expires, and was a local administrator on the machine—you can tighten down more granular I'm sure if needed—and this is the credential I used here
Print Screens
General
![enter image description here](../../I/static/images/c3e619ab0d6382d6328990e6d7e8caa9ab2d4b6eb5608de580f23eb57136e064.png)
Triggers
![enter image description here](../../I/static/images/21e2bf1925bc9d8d91236537d8161557171e15e057562cbc087a380c9305215f.png)
Action
![enter image description here](../../I/static/images/b8aa3a8113a24eafac837018ded1a4785efe732dab4c7da30ab04058a14c5d88.png)
Credential
![enter image description here](../../I/static/images/00cb9b8099cd029ac0d49ede096ba597f3c7db31b836c3d689fe9702c3435d66.png)
In the end
So, essentially after you complete the steps as described
above you should end up with a configuration as described below:
Two batch scripts; one that's scheduled to disable a NIC and another to run manually as-needed to enable a NIC
![enter image description here](../../I/static/images/2d91bd8c0a82a492de144e11f5c59b0c989fa41db7b0c28355e4fba03a48f4f6.png)
One scheduled task to execute the batch script once a minute
![enter image description here](../../I/static/images/04b6694c9dd2a9f0a09ec97849b1c60ad88109514aefa2f72bf11c0dde6f8e91.png)
One file to create and delete as needed
![enter image description here](../../I/static/images/4b999c9e55f2294a75f65458b94c3cbe3e3c66771138e85ba7f27e5636d391c8.png)
Trigger Notebook NIC Disable Operation
This means if the file of C:\Test\start.txt does not exist then the batch
script that runs once a minute will disable the NIC disrupting its network connectivity. If the
file does exist then the batch script will exit doing nothing further. The folder the "start" file resides in should be the same folder that you setup the share on and accessed from the Android already.
Since you confirmed you can delete a file on notebook Windows shared folder
from your Android, you simply connect and delete this file as needed
and you can be assured that once a minute the batch script will
disable the NIC when executed.
Preventing Notebook NIC Disable Operation
When you get back to the machine and you need to use the Internet, you
simply go to the C:\Test folder (or whatever you decide to use), right-click, New | Text
Document | name it start.txt (or whatever you decide to use) and then right-click run the
zEnableNIC.cmd
(from the folder you put that script) as administrator and the NIC will be re-enabled and you
can use the Internet again without disruption from the batch script
that still runs once a minute.
Further Resources
Comments are not for extended discussion; this conversation has been moved to chat.
– DavidPostill – 2017-08-22T19:55:11.527