I want to create a bat file to execute several series command, for example I wrote this code:
c:
netsh
advance
but the problem that the first two lines execute, but the last one didn't so the result will be as shown below:
c:\>netsh
netsh>
but the result must be :
c:\>netsh
netsh>firewall
netsh firewall>
so the firewall is sub command of netsh family so how I can solve this problem ?
thanks in advance
Use netsh -f script.txt to feed a script to netsh. Type netsh /? for details or online here: http://technet.microsoft.com/en-ca/library/cc778925(v=ws.10).aspx
Related
I am actually trying to make a script to change my network whenever I want to. But the netsh command result in an error. FYI, my OS is set to French Language.
Here is my code :
SET NomConnexion=ReseauLocal
SET IP=192.168.1.188
SET Masque=255.255.255.0
SET Passerelle=192.168.1.254
netsh interface IP set address "%NomConnexion%" static %IP% %Masque% %Passerelle% 1
SET DNS=8.8.8.8
SET DNS2=8.8.4.4
netsh interface IP set DNS "%NomConnexion%" static %DNS% primary
netsh interface ip add dns "%NomConnexion%" %DNS2% 2
Resulting with this error (x3) : "The filename, directory name, or volume label syntax is incorrect".
I also tried without quotes, but it didn't work also.
I tried to save my .bat files with notepad++ & notepad.exe, with different encoding methods, but nothing changed.
Any idea ?
I found out the solution using #Gerhard Barnard comment.
I used this :
netsh interface show interface
To display all my interfaces names, and then take the good one and apply it to NomConnexion. Everything works now. Thanx !
I am running the following command in cmd for which I am able to get the log successfully.
cd C:\Users\sriram\AppData\Local\Temp\license1.1.4
C:\Users\sriram\AppData\Local\Temp\license1.1.4>lsmon.exe testprovilic.muc.company> C:\Users\sriram\AppData\Local\Temp\license1.1.4\usage.log
Above command will generate the logs in the usage log file. But I created a batch file as below for which it is giving me an error testprovilic.muc.company not found
#ECHO off
SET variable=C:\Users\s.d.vaidyanathan\AppData\Local\Temp\usage.log
START "C:\Users\s.d.vaidyanathan\AppData\Local\Temp\license1.1.4"lsmon.exe testprovilic.muc.company> "%variable%"
Could you please help me solve this issue.
Thanks and Regards,
Sriram
You need to add the "cd C:\Users\sriram\AppData\Local\Temp\license1.1.4" to the batch file. Or use the full path to the file like:
C:\Users\sriram\AppData\Local\Temp\license1.1.4\testprovilic.muc.company
So you would have ..
#ECHO off
cd C:\Users\sriram\AppData\Local\Temp\license1.1.4
SET variable=C:\Users\s.d.vaidyanathan\AppData\Local\Temp\usage.log
START "C:\Users\s.d.vaidyanathan\AppData\Local\Temp\license1.1.4"lsmon.exe testprovilic.muc.company> "%variable%"
or you could
#ECHO off
SET variable=C:\Users\s.d.vaidyanathan\AppData\Local\Temp\usage.log
START "C:\Users\s.d.vaidyanathan\AppData\Local\Temp\license1.1.4"lsmon.exe C:\Users\sriram\AppData\Local\Temp\license1.1.4\testprovilic.muc.company> "%variable%"
This doesn't work:
"C:\Users\s.d.vaidyanathan\AppData\Local\Temp\license1.1.4"lsmon.exe
The whole path needs to be in quotes and there needs to be a backslash after the last folder name.
Change it to this:
"C:\Users\s.d.vaidyanathan\AppData\Local\Temp\license1.1.4\lsmon.exe"
Open a command prompt window, type set and press key RETURN or ENTER to run this command. You get displayed all predefined environment variables with their current values. You can see TEMP, USERPROFILE and USERNAME.
Windows command line has a help. The command to get help is help, yes really. Try it out! You need help on command CD, enter in command prompt window help cd or alternatively cd /?. You need help on command SET and START, run help set or set /? and help start or start /?. All internal commands of cmd.exe and nearly all console applications support the parameter /? and output 1 or more help pages on running the command with this parameter.
You need a better overview of standard Windows commands? See Microsoft's command-line reference and SS64's command line reference.
I assume that sriram is your user account and s.d.vaidyanathan is the user account of someone else. By default a standard user has no permissions to access folders and files in a different user's profile than the own profile since Windows Vista. That means, you logged in as sriram can't access the files and folders of C:\Users\s.d.vaidyanathan because of missing permissions to do so. It would be necessary to use command Runas to run the batch file with account s.d.vaidyanathan.
#echo off
rem Execute lsmon.exe from license1.1.4 in my folder for temporary
rem files and folders and write the log file also into this folder.
"%TEMP%\license1.1.4\lsmon.exe" testprovilic.muc.company >"%TEMP%\license1.1.4\usage.log"
Note: Double quotes must be used around path AND file name. Just double quoting parts of a file name with path may or may not work depending on error correction and how the application is written. For details see answer on set environment variables with spaces.
See also the Microsoft article Using command redirection operators.
And regarding right usage of command START not really needed here see for example answer on How to call a batch file in the parent folder of current batch file?
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.
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)
I want ot execute the following commands using batch file:
1.ftp 127.0.0.1
2.USERNAME
3.PASSWORD
4.put
5.D:\\zz.xml
6.mmm.xml
Each command is a sequence of the prev command
I want to move file from local to ftp server
I googled for that and I found that insert ; between commands is the solution but itsn't correct for me
Please support me
1 is a command on the command prompt, but 2..6 are FTP commands.
I would put lines 2..6 in a file called commands.txt then redirect that file to stdin.
ftp 127.0.0.1 < commands.txt
Edit:
You could use -s:commands.txt instead of the < according to the ftp help.
-s:filename Specifies a text file containing FTP commands; the
commands will automatically run after FTP starts.
Use a CRLF between each command.
I would rather use the expect command that allows you to script inputs according to outputs.
You can find some information here: http://en.wikipedia.org/wiki/Expect
You have an example on that page that describes exactly what you want to do.
#Albin Sunnanbo
Thanks for your reply
I solved the problem now from the following tutorial
http://www.dostips.com/DtTipsFtpBatchScript.php
I write the foillowing commnads in batch file:
FTP -v -i -s:commands.txt
then commands.txt contaisn the following commands
open 127.0.0.1
UserName
Password
put
D:\\zz.xml
mmm.xml