more G-Labs products

Author Topic: Can I disable network interface in the security module?  (Read 1308 times)

March 08, 2014, 04:57:21 AM
Read 1308 times

naps1saps

  • ***
  • Information
  • Full Member
  • Posts: 79
I would like to disable the network adapter if no internet connection is present so my cell data modem will connect to send alerts if the cable is cut or power is out.  Found some code but it will not run probably because it needs some includes or uses data.  Also I need a ping statement if possible.

METHOD 1
Code: [Select]
Process.Start("cmd.exe","/c netsh interface set interface 'Local Area Connection' DISABLED");
METHOD 2
Must declare System.Management
Code: [Select]
SelectQuery wmiQuery = new SelectQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionId != NULL");
ManagementObjectSearcher searchProcedure = new ManagementObjectSearcher(wmiQuery);
foreach (ManagementObject item in searchProcedure.Get())
{
    if (((string)item["NetConnectionId"]) == "Local Network Connection")
    {
       item.InvokeMethod("Disable", null);
    }
}
« Last Edit: March 08, 2014, 05:07:40 AM by naps1saps »

March 12, 2014, 02:22:11 AM
Reply #1

naps1saps

  • ***
  • Information
  • Full Member
  • Posts: 79
Anyone know how to get this code to run in the module?