Announcement

Collapse
No announcement yet.

disable lan connection

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Rush113
    replied
    Ok i got it working Kinda
    It only works if the name doesn't contain spaces.
    Ethernet, Lan, Lan1...etc.
    if it's a two or more word name it won't work.

    Any ideas on how to fix this would be very much appreciated.

    For those who are interested.

    First i created a bat file and saved it to my scripts folder:
    Code:
    @Echo Off
    For /f "skip=2 tokens=2*" %%a In ('netsh interface show interface') Do (
        Call :UseNetworkAdapter %%a "%%b"
    )
    Exit /B
    
    :UseNetworkAdapter
    :: %1 = State
    :: %2 = Name (quoted); %~2 = Name (unquoted)
    If %1==Connessione (
        :: Do your stuff here, for example:
        Echo %~2> mylan.txt
        setlocal enableextensions disabledelayedexpansion
    
        set "first=1"
        <nul (
          for /f "usebackq delims=" %%a in ("mylan.txt") do (
            if defined first (set /p ".=%%a" & set "first=") else (set /p ".=,%%a")
          )
        ) >"lan.txt"
    del mylan.txt
    )
    Exit /B
    This creates a text file called "lan.txt" with this text:
    Dedicato Ethernet
    I'm running on an Italian OS so you will get the first word in your language. This will have to be modified later on.

    Next in the "On Preload" tab i put this code:
    Code:
    Shell.Execute("AutoPlay\\Scripts\\lan.bat", "open", "", "AutoPlay\\Scripts\\", SW_HIDE, false);
    Finally i created a Toggle Button named LAN and placed this code in the "On Click" tab:
    Code:
    lan = System.GetLANInfo();
    lan_exist = true;
    for j in pairs(lan) do
        if lan[j] == "Unknown" then
            lan_exist = false;
        end
    end
    
    if lan_exist then
    	Button.SetState("LAN", BTN_DOWN);
    		sString = TextFile.ReadToString("AutoPlay\\Scripts\\lan.txt");
    		myLan = String.TrimLeft(sString, "Dedicato         ");
    		CommandLine.Execute("netsh interface set interface "..myLan.." DISABLED", 0);
    
    else
    	Button.SetState("LAN", BTN_UP);
    		sString = TextFile.ReadToString("AutoPlay\\Scripts\\lan.txt");
    		myLan = String.TrimLeft(sString, "Dedicato         ");
    		CommandLine.Execute("netsh interface set interface "..myLan.." ENABLE", 0);
    end
    This is where the modification takes place.
    Change:
    myLan = String.TrimLeft(sString, "Dedicato ");
    to whatever text you have in your language just before the actual name of your LAN, including all spaces too. (Check the "lan.txt" file that is created by the "lan.bat" file.)

    NOTE: You need the "CommandLine" plugin for this to work.

    Hope this might be usefull to someone, and if there is a much cleaner way to go about it, please enlighten me.

    Leave a comment:


  • Rush113
    started a topic disable lan connection

    disable lan connection

    Good day everyone, i'm hoping someone can help me with what most likely is a simple solution but i just can't seem to find it:

    I have a button with the code
    Code:
    result = CommandLine.Execute("netsh interface set interface Ethernet DISABLED", 0);
    this works fine.

    My problem is that the LAN connection name is not always the same.
    In this case the name is "Ethernet" but it could vary to, for example, "Local Area Connection" or to whatever the user names it.

    How would i go about retrieving the actual name to be able to use it as a variable?

    Thanx in advance.
Working...
X