Use the DevCon tool to restart your wireless card device with batch processing

Source: Internet
Author: User

Recently, due to work needs, wrote a batch to restart the wireless network card.

First of all, say something about my idea:

1. Ping the Gateway (default option, Gateway is 192.168.1.1) two times, if successful, the batch finishes

2, if not successful, the second time, restart the wireless network card

in order to achieve the above purposes. I need a tool that allows you to enable, disable, restart, update, delete, and query a single device or set of devices in a DOS command. And DevCon is just the tool for doing these things in Windows. It is not integrated in the Windows default installation, so we need to download the tool via our website or other websites. Since the official tool is not working properly in Win7 64bit, I recommend downloading to the following website:

http://download.csdn.net/detail/zhangzxing/5691253

Download the good files and unzip them. DevCon in 3 files: AMD64, i386, ia64. Copy the version of the operating system to the System32 directory of the system disk. According to the idea, write the batch process:

@echo off

for/f%%y in (' DevCon find usb\* ^|find ' MER ') do set wlid= "@%%y"

:: Crawl the hardware ID of the wireless card, I'm using mercury, so look for the "MER" included.

:: The quotation marks are added to the%%y to assign values as a whole string of%%y values. Otherwise the variable assignment will be intercepted

:: Because the value in%%y is recognized by DOS as a system path, it may contain a special symbol &

:: The reason for adding @ is because of this, the string as a whole to execute

:: Because the DevCon program corresponds to the execution mode, DevCon restart "@ Hardware ID", so the wlid variable value just matches the condition

set/p targie=<c:\ip.txt:: Enter the IP address from the file

For%%i in (on) do (:: Loop

Ping-w 1%targie% >c:\123.txt:: Network test

If%errorlevel%==0 (

:: Determines whether the ERRORLEVEL variable records the status of the last program execution, 0 is successful, and the other is failed

echo "%date%:%targie% is comneted!" :: The program executes successfully, then the output date and success information

) Else (
If%%i==2 (
echo "NETWORK SERVICE restarting ..."
DevCon restart%wlid%:: If the ping is unsuccessful and has been done two times, restart the NIC

If%errorlevel%==0 (
echo "NETWORK SERVICE is restarted!"
) Else (

echo "Network SERVICE restart Fail":: Determine the success of the NIC restart, and the corresponding prompt

) Else (
Echo Trying%%i time to comnetting%targie%:: If the ping is unsuccessful, the. Prompt is attempting to connect to Gateway 1, 2 times
)

)
)

Problems that arise:

After the ping, DevCon command executes, sometimes the value returned by the%errorlevel% error occurs.

This issue is not resolved. Still looking for a better way to judge.

Another, DevCon's detailed introduction, please see Baidu Encyclopedia)

Parameter editing

Devcon.exe [-R] [-m:\\<machine>] <command> [<arg> ...]

-R If it is specified, restart the computer if necessary after the command completes.

<machine> is the name of the target computer.

<command> is the command to be executed (as shown below).

<arg>, ..... is one or more parameters required by the command.

To get help on a particular command, type: Devcon.exe <command>

Classfilter allows you to modify the category filter.

Classes lists all device installation categories.

Disable disables devices that match the specified hardware or instance ID.

Driverfiles lists the driver files that are installed for the device.

Drivernodes lists all the driver nodes for the device.

Enable enables devices that match the specified hardware or instance ID.

Find finds a device that matches the specified hardware or instance ID.

FindAll find devices, including those that are not displayed.

Help displays this information.

Hwids lists the hardware ID of the device.

Install the device manually.

ListClass lists all devices for an installation category.

Reboot restart the local computer.

Remove removes a device that matches a specific hardware or instance ID.

Rescan scan to discover new hardware.

Resources lists the hardware resource for the device.

Restart restart the device that matches the specific hardware or instance ID.

Stack lists the expected device driver stacks.

Status lists the operating state of the device.

Update manually updates the device.

Updateni manually updating the device without user prompting

Sethwid Add, remove, and change the order of the hardware IDs of the root enumeration devices.

3

This article is from the "Easou" blog, make sure to keep this source http://242337.blog.51cto.com/232337/1605262

Use the DevCon tool to restart your wireless card device with batch processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.