[Batch] The Official Batch File Repository - Learn & ask questions about batch files

Discussion in 'Scripting' started by timesurfer, Oct 11, 2010.

  1. sanjose

    sanjose MDL Member

    Jan 23, 2012
    184
    21
    10
    Hi all,

    I need a .cmd or .bat file so that when I run it will automatically disconnect internet in 30 seconds and then it re-connects internet again. Would you please help me with the command lines.

    Thanks so much in advance.
     
  2. leebo_28

    leebo_28 MDL Senior Member

    Jun 12, 2011
    465
    172
    10
    ECHO ON

    netsh interface set interface name="Local Area Connection" admin=DISABLED

    TIMEOUT 30

    netsh.exe interface set interface name="Local Area Connection" admin=ENABLED

    would have to be run as Administrator.. and "local Area Connection" changed as necessary
     
  3. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,466
    990
    60
    WOW. Welcome to the community leebo 2.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. sanjose

    sanjose MDL Member

    Jan 23, 2012
    184
    21
    10
    #324 sanjose, Dec 18, 2013
    Last edited: Dec 18, 2013
    This command is for Local Area Connection only.

    Can you show me the command lines for both Local Area Connection and Wireless.

    I mean that When I run this command ..... It will automatically disconnect Local Area Connection or Wireless if one of 2 appears.

    Thanks a lot in advance


     
  5. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,466
    990
    60
    netsh interface set interface name="wi-fi" admin=disable

    replace wifi with what ever your wireless connection name is which you can find out with: netsh wlan show interface

    It will be, mine for example:

    Name : Wi-Fi

    which is where I got Wi-Fi in:
    netsh interface set interface name="wi-fi" admin=disable
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. sanjose

    sanjose MDL Member

    Jan 23, 2012
    184
    21
    10
    #326 sanjose, Dec 18, 2013
    Last edited: Dec 19, 2013
    @Humphrey
    Thanks for your reply. I'm a little confused that one of mine is WI-FI and other is WI-FI 3.
    Therefore I must replace interface name as I run. I wonder whether or not we can use a command to disable or enable no matter what it is Wireless or Local Area Connection.

    like Josh Cell " Advanced Tokens Manager - The Activation Backup Solution "

    Do you have any ideas ?

    Thanks for your concern.
     
  7. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,466
    990
    60
    #327 Humphrey, Dec 18, 2013
    Last edited by a moderator: Apr 20, 2017
    You will have to have a line for each one.


    Disable_Enable_w.Lan.bat
    Code:
    @ECHO OFF
    netsh interface set interface name="wi-fi" admin=disable
    netsh interface set interface name="wi-fi 3" admin=disable
    netsh interface set interface name="Local Area Connection" admin=DISABLED
    TIMEOUT 30
    netsh interface set interface name="wi-fi" admin=ENABLED
    netsh interface set interface name="wi-fi 3" admin=ENABLED
    netsh interface set interface name="Local Area Connection" admin=ENABLED
    EXIT
    Run as admin.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. sanjose

    sanjose MDL Member

    Jan 23, 2012
    184
    21
    10
    @Humphrey

    Thanks so much for your help. Have a nice day.
     
  9. oneextraid

    oneextraid MDL Member

    Jul 29, 2009
    181
    19
    10
    I have a cmd file that I wrote to backup partitions, to an external hard drive, using Macrium Reflect. The problem I have is that I don't always get the same drive letter when I attach the drive and the script fails.

    Is there some way to find the drive letter within the script, that is assigned to my external hard drive labelled "Toshiba", so that my script can handle any drive letter assigned?
     
  10. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    #330 s1ave77, Mar 26, 2014
    Last edited by a moderator: Apr 20, 2017
    You can search for a specific file on the drive to determine, like in the example:

    Code:
        for %%d in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
            if exist %%d:\sources\install.wim (
                set path2=%%d:
            )
        )
    
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. oneextraid

    oneextraid MDL Member

    Jul 29, 2009
    181
    19
    10
    Thanks I will try it.
     
  12. oneextraid

    oneextraid MDL Member

    Jul 29, 2009
    181
    19
    10
    Can I use the "if exist %%d:\Backups" for just the presence of a folder with no file?
     
  13. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    #333 s1ave77, Mar 26, 2014
    Last edited by a moderator: Apr 20, 2017
    I would create a text file like 'Toshiba.txt' in root folder of the drive and then use (a slightly shortened form :D):

    Code:
    for %%d in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
            if exist %%d:\Backups set path=%%d:
        )
    Yep, should work :good3:. See the shortened form above :cool2:.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. leebo_28

    leebo_28 MDL Senior Member

    Jun 12, 2011
    465
    172
    10
    couldn't you just change the drive letter of external to "Z" , then when you plug it in , it will always assign the letter "Z"
     
  15. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    Afaik this won't work on other machines :g:.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  16. leebo_28

    leebo_28 MDL Senior Member

    Jun 12, 2011
    465
    172
    10
    #336 leebo_28, Mar 27, 2014
    Last edited by a moderator: Apr 20, 2017
    Code:
    for /f %%D in ('wmic volume get DriveLetter^, Label ^| find "Toshiba"') do set usb=%%D
    This will select drive by volume name..
     
  17. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    #337 s1ave77, Mar 27, 2014
    Last edited by a moderator: Apr 20, 2017
    Yeah, that's indeed sophisticated :good3:. [copy 'n paste it]
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  18. leebo_28

    leebo_28 MDL Senior Member

    Jun 12, 2011
    465
    172
    10
    #338 leebo_28, Mar 27, 2014
    Last edited: Mar 27, 2014
    shoot..i'm a google search pro! :cheers: Never claimed I wrote it..just found a solution..
     
  19. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,104
    24,378
    340
    No problem, as long as someone finds such nice solution. Most probably anybody already invented the wheel, problem is mostly to find it ...:cool2:.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  20. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    #340 Compo, Mar 27, 2014
    Last edited by a moderator: Apr 20, 2017
    Try This:
    Code:
    @For /f "UseBackQ Tokens=1* Delims==" %%a In (
    `Wmic LogicalDisk Where "VolumeName='TOSHIBA'" Get DeviceID /Value`
    ) Do @(If '%%b Neq ' Call :StartMe %%b)
    @GoTo :Eof
    :StartMe
    @Echo Off
    SetLocal
    Set USB=%1
    Now that the DriveLetter is defined as %USB% just put the rest of your script content at the bottom.