my laptop has a faulty Wifi Adapter, and every time I disconnect from the internet (5-10 times a day), I have to click "troubleshoot problems". Windows goes through a whole process to find the problem and then resolves it, but I know the solution is just to reset the Wifi Adapter. So I figured there would be specific commands in cmd for that. I thought I could make a batch file that would run the specific commands in cmd, because that would probably be faster than using the troubleshooting feature. Problem is, I have no idea how to program in batch. May anyone help me?
Had the same issue, tried Junaid's solution, but it didn't work for me.
This helped me, however.
TL;DR:
netsh interface set interface <interface name> DISABLED
netsh interface set interface <interface name> ENABLED
On my machine < interface name> is WiFi, for instance.
Does require admin rights, so it's probably best to make a shortcut to the batch file. I turned it into an executable and pinned a shortcut to it in the taskbar.
Start elevated Command Prompt.
::Get NIC list and index number:
wmic nic get name, index
Now create a something.bat file and put these commands
::Disable NIC with index number: (eg: 7)
wmic path win32_networkadapter where index=7 call disable
::Enable NIC with index number: (eg: 7)
wmic path win32_networkadapter where index=7 call enable
you will need to replace 7 with index number of your interface.
I tried the 4 lines of code and had to make sure the device # in place of the "(eg: 7)" on lines 1 and 3 was typed without the space between the : and the # (eg, ...index number:7)
Related
So, I am currently trying to create a batch file to connect to a wireless network. So far I have the following...
#echo off
netsh wlan connect ssid="My SSID" name="My Name"
pause
It works fine, but the issue is that it can only connect to networks that are already in my profiles. Is there any way that I can connect to a wireless network, using a password as an argument, that is not already in my profiles?
You need a xml file that has the SSID and password.
<?xml version="1.0"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
<name>{example}</name>
<SSIDConfig>
<SSID>
<hex>{6578616d706c65}</hex>
<name>{example}</name>
</SSID>
</SSIDConfig>
<connectionType>ESS</connectionType>
<connectionMode>auto</connectionMode>
<MSM>
<security>
<authEncryption>
<authentication>WPA2PSK</authentication>
<encryption>AES</encryption>
<useOneX>false</useOneX>
</authEncryption>
<sharedKey>
<keyType>passPhrase</keyType>
<protected>false</protected>
<keyMaterial>{password}</keyMaterial>
</sharedKey>
</security>
</MSM>
<MacRandomization
xmlns="http://www.microsoft.com/networking/WLAN/profile/v3">
<enableRandomization>false</enableRandomization>
</MacRandomization>
</WLANProfile>
Fill in the {6578616d706c65}, {example}, {example} and {password} with your own information.
{6578616d706c65} is the Hex of example, click here to convert ASCII to HEX.
Make sure you use the correct format, windows WILL NOT accept even there's one more space at the end.
click here to download example.xml and other files.
If you want to use pure cmd to connect (without changing the {password} manually), keep reading
To do this, you will need 36 xml files with a-z and 0-9 (it's not possible to have both caps and lowercase.)
click here to download the 36 files and example.xml.
First you need to separate example.xml into 3 parts, the first part is from <?xml version="1.0"?> to <keyMaterial>.
Name that to T.xml.
The second part is the password.
The third part is from </keyMaterial> to the end (</WLANProfile>) make sure you don't forget the line break after </WLANProfile>.
Name that to B.xml.
Then you will use the copy command to combine the files.
The code should look like this
copy /y C:\T.xml + C:\keyMaterial\p.xml + C:\keyMaterial\a.xml + C:\keyMaterial\s.xml + C:\keyMaterial\s.xml + C:\keyMaterial\w.xml + C:\keyMaterial\o.xml + C:\keyMaterial\r.xml + C:\keyMaterial\d.xml + C:\B.xml C:\example.xml /B
netsh wlan add profile filename="C:\example.xml" user=all
netsh wlan connect example
Finally, you can check if you're connected by running ping google.com.
Not with a single netsh command. You'll need to have a profile for the network. If you know the security settings of the network you would like to connect to, your batch file can use netsh to import a profile with the SSID/password you want to connect, then use netsh to connect to that profile. Your batch file would have to assemble the profile xml. However, this approach is very brittle because if a network does not match the security settings in your generated profile, the connection won't succeed.
You could attempt to use other commands of netsh to infer the security settings and try to cobble together a profile to match an arbitrary network, but that opens a whole new can of worms.
I can't really recommend either approach, but if you want to export/import profiles, the commands are
netsh wlan export profile "<profile name here>"
netsh wlan add profile <xml filename here>
This is my code. I am making an IP finder, for Fun and practice. I want to log all of the successful IPs on a separate line for each IP. As a note, successful meaning any IPs that I get a reply from.
:ModeB
CLS
Echo AutoMode On
ping %RANDOM:~-2%.%RANDOM:~-3%.%RANDOM:~-3%.%RANDOM:~-3%
goto ModeB
Basically, this will randomly generate numbers within dots and ping it. It does this repeatedly. Most of these IPs will not work, but it will get replies from some of them. I want to log the IPs I get at least one reply from, and then, and only then, will it truly be an IP finder. Any advice for this project will be appreciated.
There is enough bad willed traffic in the internet, there is no need
to be obtrusive.
%Random% generates numbers between 0 .. 32768 see here
an ip octet is 0 .. 255
your approach has the problem that while verifying the success of your ping you have to store the ipaddress, the next invocation of %random% has another random result.
You should read on redirection, for /f to parse the output of a command etc. ss64.com is a good starting point.
And please choose a different learning object-
To start with, there are much more effective ways of scanning lots of ip's to see which are active, such as the free, open source tool nmap.
Using this method to find active hosts will most likely never find any considering the shear amount of possibilities an ip could be.
I'm not entirely sure batch actually has the capabilities to do what you are looking for, so I would recommend looking into other languages. As a recommendation, VB.NET and Python are good places to start.
I want to run the following commands through a batch file.
netsh
wlan
connect name=NETWORK-NAME
The issue is that 'netsh' and 'wlan' are unable to be done in the same line using conventional delimiters (&, &&). If I run this string as a batch file:
echo 1 & netsh & echo 2 & wlan & echo 3 & connect name=NETWORK-NAME
It outputs 1, activates netsh and stops there without executing the rest of the batch file.
I know this is an older post, but info on the internet is forever.. so..
That actually won't work. NETSH is, itself, a shell like DOS is (now). You can execute that on a command line directly, but not in a batch file. Using NETSH in Batch mode is a little more complex and, in this instance, would require 2 batch files. One to launch NETSH, and another for NETSH to execute after launch.
Here is a good post on how it should be done:
https://www.techrepublic.com/article/build-your-skills-netsh-scripts-add-network-functionality-to-batch-files/
Hope this helps someone who stumbles across this.
netsh is a program that can run either in interactive mode when you enter the program and you enter command modifiers and switch contexts one by one per line or just run the required operation in the required contect immediatelly.
So you just need to make a single string:
#echo off
netsh wlan connect name=profile_name ssid=SSID_name interface="Wirelss network adapter"
Note that ssid and interface are optional. You need to specify interface if you have several wirelss network adapters in your system - it corresponds to the adapter name. And you need to specify ssid if there are multiple SSIDs in your saved wireless network profile.
I'm trying to send network credentials using Net Use command.
This is what I have:
#echo off
net use \\<serverName>\<shareFolder>\ passw0rd /USER:domain.com\UserName
PAUSE
This automatically inserts the username and Domain but for some reason not the password!!
I have tried it like this as well:
#echo off
net use \\<serverName>\<shareFolder>\ /USER:domain.com\UserName passw0rd
PAUSE
I have checked the paths I'm using and they definitely work. When i copy them out and paste in RUN they work.
Same goes for the username and passwords.
Everything in google search is purple cause I've clicked on all the links :/
Ok, I thought I had it...
I tried it like this:
#echo off
net use \\<serverName>\<shareFolder>\ <mapName> /USER:domain.com\UserName passw0rd
PAUSE
And it worked, but only because i entered the password before i tried it like this and then it remembered the password.
So I'm still looking for a way.
Please help.
Does the password contain special characters like % / ~ or similar characters with special meaning in batch files?
Yes, then enclose the password in double quotes.
Use also double quotes around UNC path and test if that makes a difference.
What I miss in all your net use commands is the device name usually specified left of UNC path to shared folder to map the shared folder to a drive letter. Therefore it could be that the password is interpreted as device name.
But according to your question you want to pass only the user credentials and password to be able to access the shared folder using UNC path. However, I suggest to test if it makes a difference really mapping the shared folder to a drive letter. I don't know if the password string is interpreted as device name if no device name specified and can't test it by myself at the moment.
#echo off
net use <MapDriveName> \\<serverName>\<ShareFolder>\ /PASSWORD:<Passw0rd> /USER:<UserName>
PAUSE
This one works for me. Finally :)
Hope this can help someone else as well.
net use Y: \server_name OR ipaddress\shared /user:domainname\%username%
I am trying to get a couple scripts to work with each other, but I am not entirely familiar with the if-then commands, I am using wizapp and I have my info ready to go, but I don't know how to map a specific location based on the output of wizapp, as a for instance
if %siteid%=="0"
How do I map that to a drive, I have 10 different drives that have to be mapped using that
info, and I am lost, siteid will obviously be different in each if then statement?
This is relatively easy to do. I will provide manual instructions as it is extremely useful to learn and will improve your coding skills.
C:\windows\system32> net view
Server Name Remark
---------------------------------------------------------------------------------
\\PC1
\\PC2
\\PC3
\\PC4
\\PC5
\\PC6
\\PC7
\\PC8
\\PC9
\\SERVER
The command completed successfully.
C:\windows\system32> net view \\PC1
Shared resources at \\PC1
Share name Type Used as Comment
-------------------------------------------------------------------------------
SharedDocs Disk
The command completed successfully.
C:\windows\system32> net use ( Drive letter A-Z ) \\PC1\SharedDocs
The command completed successfully.
Now open up My Computer and youll see that PC1 is registered as a drive onto your computer.