Windows – Trigger an action on a Windows machine from an Android phone via network

androidbatchwindows

My Problem

I have an Internet connection in my house and many of my friends come over everyday and always want to use my notebook to access the Internet.

I don't want to be mean and tell them no that they cannot use my notebook to browse the Internet so often as this may have negative consequences with my friendships with these people.

I would like to disrupt their experience remotely from my Android phone connected to the same local network as the Windows machine someway in a secretive manner.


My Idea

I have software on my Android phone, and I setup a shared folder on the Windows 7 machine and confirmed I can create and delete files in this location from my Android when connected on the same network.

I need a way to utilize this shared folder and trigger some sort of task or batch script on the Windows machine from my Android as needed that will disrupt the network of my notebook.

If I can get the network on the notebook to be disrupted or something then this would trick people into thinking the notebook doesn't work very well at all and they'd stop asking to use so often.


Question

I already know how to make a batch file that makes a computer freeze but I'm not sure where to start to trigger a batch script or something to run on the Windows machine with the shared folder access I have from the Android to create and delete files. Any way to help make this task possible?

Best Answer

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

enter image description here


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"

    • Begin the task: On a schedule
    • Settings: One time
    • Repeat task every 1 minutes
    • for a duration of indefinitely

    • Check Wake the computer to run this task

  • 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

Triggers

enter image description here

Action

enter image description here

Credential

enter image description here


In the end

So, essentially after you complete the steps as described above you should end up with a configuration as described below:

  1. 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

  2. One scheduled task to execute the batch script once a minute

    enter image description here

  3. One file to create and delete as needed

    enter image description here

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

Related Question