Enable Disable XP WIFi using command line - batch-file

Help me out to, Enable and Disable WIFI in my XP using Command Line.
Tried with:
netsh interface set interface name="Wireless Network Connection " admin=disabled
but it is showing, More data to display.
Also, "netsh interface show interface"
Does not display any Interface name.
Thanks in Advance.

That's command should work fine. Are you sure it's not disabled? is there really connection available with name Wireless Network Connection?
In your command, try replacing Wireless Network Connection with actual connection name like Local Area Connection
netsh interface set interface name="Local Area Connection" admin=disabled
Also if below command is not displaying then I doubt, you have any network interface configured. Check to make sure that.
netsh interface show interface
You can as well use the below alternative way to enable/disable a specific connection [Quoted from MS Community Answer]
Start elevated Command Prompt.
Get NIC list and index number:
wmic nic get name, index
Enable NIC with index number: (eg: 7)
wmic path win32_networkadapter where index=7 call enable
Disable NIC with index number: (eg: 7)
wmic path win32_networkadapter where index=7 call disable

Related

Batch script to enable a disabled network adapter with different names

I'm writing a script to revert the network settings back to default which is to switch back to DHCP on LAN and re-enable the wireless adapter. All these operations were done under the local admin rights privileges for all devices that I'm managing.
While the switching over to DHCP from static works, the script was unable to re-enable the wireless adapter and showing "No more data is available". I had did a bit of troubleshooting and found out that the disabled wireless adapter is not reflected in the ipconfig /all command which I have been using it to obtain the adapter name (e.g Wi-Fi, Wi-Fi 2, etc.) thus the netsh command gave the error due to the varible being invalid.
Here is the part of the code that's responsible for the re-enabling the wireless adapter back. I'm aware that if I were to enter the netsh interface set interface name="Wi-Fi" admin=enabled manually it works based on the adapter name that's taken on my test device. But however I can't hard-code the adapter name as it may not be the same for different devices. Do share if there's any other code for the first line that I might not be not aware of as I did many googling and it only came up with either for the ipconfig or wmic command. Thanks!
::Look for the Wi-Fi adapter name
for /f "tokens=* delims=:" %%b in ('ipconfig ^| find /i "Wireless LAN adapter Wi-Fi"') do set wifiadaptername=%%b
set wifiadaptername=%wifiadaptername:~21%
set wifiadaptername=%wifiadaptername:~0,-1%
::Switch on Wi-Fi
netsh interface set interface name="%wifiadaptername%" admin=enabled

How to force DHCP on all phyiscal ports, including Disconnected Media ports, with WMIC

Could anyone help me force all network adapters to be DHCP whether connected or disconnected.
I am relatively new and very novice in batch and I have been working on something to set fixed ipv4 details based on variable Ethernet adapter names. It has been cobbled together from other people's solutions to various problems on here. I am sure there are much more eloquent and elegant ways of doing this and happy to be pointed that way but I would like to try and figure this out.
The idea was to have a call batch script in the startup folder of a OOBE windows machine. Search the connected adapter, irrelevant of the name of said port, set the IP address as static and rest of the details were fixed. I wrote the batch in such a way as to create various IP profiles using variables to create the profile to set the fixed details i.e. a batch to write a batch
As an exercise I was thinking if I were to move the machine and plug in a different adapter on the same machine. How would I have a disconnected adapter with the IP address I want to use switch to DHCP. This would free up the address to search for connected adapter as per the rest of the script. This is where the script fails. I can have the connected adapter switch tp DHCP, disable and enable correctly.
WMIC NICConfig Where "IPEnabled='True' and DHCPEnabled='FALSE'" Call EnableDHCP
this works but only on the connected adapter.
But I am trying to flush out the IP address on the disconnected adapter to use on the connected adapter. So far I've tried
WMIC NICConfig Where NetConnectionID=7 Call EnableDHCP
returns a "Description = Invalid query"
WMIC NICConfig Where "PhysicalAdapter='True'" Call EnableDHCP
returns a "Description = Invalid query"
WMIC NICConfig Where "DHCPEnabled='FALSE'" Call EnableDHCP
returns {ReturnValue = 84;}; I thought this would search for adapters that were not DHCP and change to to be DHCP but I think the adapter has to be connected.
When I use
WMIC NICConfig Where "PhysicalAdapter='True'" Call /?
EnableDHCP looks to be an option but gives a "Description = Invalid query"
Is there a way to do what I am trying to do?
I can also post the entire script if anyone is interested in it but will leave it off until requested. Thanks in advance for any help.
I figured this out.
I was going about it the complete wrong way.
I was trying to clear all adapters fixed ip addresses by "forcing" the physical adapter to DCHP weather connected or disconnected.
But if I have had said
netsh int ip reset
wmic path win32_networkadapter where PhysicalAdapter=True call disable
wmic path win32_networkadapter where PhysicalAdapter=True call enable
This achieves what I want. This clears the IP, subnet and gateway. Sometimes the solution is much easier than expected.
Is there a way to clear the DNS information too for all physical adapters, without knowing their names, so that if IPV4 properties is open no information would be there?

Connect to an ad-hoc-network in windows 10 only via command line

I am currently writing a .bat script in which you can choose whether you want to create an ad-hoc-network or connect to one, to make it easy for everyone to connect within windows 8, 8.1 and 10 as the GUI setup was removed.
Well, creating was easy.
netsh wlan set hostednetwork mode=allow ssid=adhocnetwork key= password
netsh wlan start hosted network
pause
But when I want to connect to a network via netsh wlan connect adhocnetwork, it says there is no profile called 'adhocnetwork'.
I figured that you first have to create a profile with the network GUI.
So my question is now if there is a way to create a network profile with the command line, so that I can implement that into the bat file.
Thanks for every answer!
Best greetings,
Bant
Okay, well, here is my workaround.
Go to the network and sharing center (hope that's right, my system is in German)
Manually create wireless network and type in the name, security type and key.
Remove the tag from 'connect automatically'.
Press 'Done'
Now open the command line and type in the following lines:
netsh wlan set profileparameter name=%name% ConnectionType=IBSS
netsh wlan connect name=%name%
I am still hoping for a better solution where you don't need to leave the command shell.

Check Windows Network Interfaces and enable them if down with batch file

I am new to batch file/script...Anyway, on my Windows server, I have two interfaces:
Interface-1(Local Area Connection 2) has, say,
10.0.77.200/16 and configured with a default gateway
Interface-2(Local Area Connection 3) has, say,
10.0.50.200/30 and no default default gateway configured.
I am looking for a simple way to create a simple batch to check these 2 interfaces, if either one or both are down, I want the batch script to re-enable them automatically.
Thanks,
Lenna -
The netsh interface show interface command will return information about the state of the interfaces. Instead of checking to see if one is down, I would just recommend running the netsh interface set interface commands to enable them as it will be much easier and won't hurt anything:
netsh interface set interface name="Local Area Connection 2" admin = ENABLED
netsh interface set interface name="Local Area Connection 3" admin = ENABLED

Can I enable/disable a network connection from the command-line or MS-Dos?

I want to enable/disable a network connection from the command-line in Windows 8.
netsh interface set interface “Local Area Connection” DISABLED
To enable the interface, you'd then run:
netsh interface set interface “Local Area Connection” ENABLED
When I try this, it generates an error message which states that "no more data is available".
This may be enough for you if you are using DHCP.
Disable:
ipconfig /release *
Enable:
ipconfig /renew
This works for me:
netsh interface set interface name="Local Area Connection" admin=DISABLED
Technical Note: There are several names associated with a network adapter on Windows API level, occurring in Struct PIP_ADAPTER_ADDRESSES
PIP_ADAPTER_ADDRESSES::AdapterName
PIP_ADAPTER_ADDRESSES::Description
PIP_ADAPTER_ADDRESSES::FriendlyName
FriendlyName is a unique logical name like "WLAN 3", generated by the system
and the one displayed with ipconfig and required in netsh interface ....
Description is the tag displayed with ipconfig /all

Resources