| 1. |
Solve : Please help me with a batch file? |
|
Answer» Ok so it does what it is supposed to but i am not going to give the full code of everything )>C:\IP_Changer\Profiles\%prof_name_1%.bat You need to explain what you intend to do. That way you get more help quicker. Quote from: Geek-9pm on December 22, 2015, 08:25:25 PM What is this? Sorry i am trying to make it so that you can change your static IP a friend ask me to make this for him but so that he can geate profile (It makes the bat file with all the stuff in it but doesnt change the bat files name) and then just choose the IP he wants here is the full code of everything: (Note: The rem is just for making it easy to write) EDIT: Code: [Select])>C:\IP_Changer\Profiles\%prof_name_1%.bat is just for the location where it saves the bat file and it works but i cant get the bat files name to change Code: [Select]:menu cls @echo off title IP Changer echo -------------------------------------------------------------------------------- echo IP Changer by Inforcer25 echo -------------------------------------------------------------------------------- echo. echo. echo. echo. echo. echo Select a Option echo ================ echo. echo [1] Set Static IP [4] Make Profile echo [2] Reset DHCP [5] Delete Profile echo [3] Use Profile [6] Exit echo. set /p op=Enter Option: if %op%==1 goto set_static_ip if %op%==2 goto set_dhcp if %op%==3 goto use_profile if %op%==4 goto make_profile_1 if %op%==5 goto del_profile if %op%==6 goto exit goto error rem ======================================================================================================================================= :set_static_ip cls @echo off echo "Please enter Static IP Address Information" echo "Static IP Address:" set /p IP_Addr= echo "Default Gateway:" set /p D_Gate= echo "Subnet Mask:" set /p Sub_Mask= echo "Setting Static IP Information" netsh interface ip set address "LAN" static %IP_Addr% %Sub_Mask% %D_Gate% 1 netsh int ip show config pause goto menu rem ======================================================================================================================================= :set_dhcp cls @ECHO OFF ECHO Resetting IP Address and Subnet Mask For DHCP netsh int ip set address name = "LAN" source = dhcp ipconfig /renew ECHO Here are the new settings for %computername%: netsh int ip show config pause goto menu rem ======================================================================================================================================= :use_profile @echo off cd C:\IP_Changer\Profiles cls echo. echo. echo. echo. echo Please enter the profile name. echo. set /p profile=Profile name: call %profile%.bat goto profile_used goto no_profile :no_profile cls echo. echo. echo. echo ERROR! echo That Profile does not exist! echo. echo. ECHO Press any key to go back pause >nul goto use_profile :profile_used cls echo. echo. echo. echo The profile you selected has now been used! ping localhost -n 3 >nul goto menu rem ======================================================================================================================================= :make_profile_1 cls @echo off if not exist "C:\IP_Changer" mkdir C:\IP_Changer\Profiles echo. echo "Profile name: (no space)" set /p %prof_name_1%=Profile name: echo. echo "Please enter Static IP Address Information" echo. echo "Static IP Address:" set /p make_IP_Addr=Static IP Address: echo. echo "Default Gateway:" set /p make_D_Gate=Default Gateway: echo. echo "Subnet Mask:" set /p make_Sub_Mask=Subnet Mask: echo. ( echo echo "Setting Static IP Information" echo netsh interface ip set address "LAN" static %make_IP_Addr% %make_Sub_Mask% %make_D_Gate% 1 echo netsh int ip show config echo pause )>C:\IP_Changer\Profiles\%prof_name_1%.bat goto prof_made :prof_made cls echo. echo. echo. echo. echo The profile has now been made! echo. echo Press any key to exit! pause >nul exit rem ======================================================================================================================================= :del_profile @echo off cd C:\IP_Changer\Profiles cls echo. echo. echo. echo. echo Please enter the profile name. echo. set /p del_profile=Profile name: call %del_profile%.bat goto profile_del goto no_profile_del :no_profile_del cls echo. echo. echo. echo ERROR! echo That Profile does not exist! echo. echo. ECHO Press any key to go back pause >nul goto use_profile :profile_del cls echo. echo. echo. echo The profile has now been deleted! ping localhost -n 3 >nul goto menu rem ======================================================================================================================================= :error cls echo. echo. echo. echo. echo. echo. echo OOPS! Wrong Number echo. echo. pause goto menu rem ======================================================================================================================================= :exit exit rem ======================================================================================================================================= Somme one could tell you, but you ought to learn now to DEBUG. You write little bits of code nips and test them one at a time. Code: [Select]C:\IP_Changer\Profiles\%prof_name_1%.batThat was not written correctly. What part of the code does that? Make it in to a little bit you can invoke. Like just two or three lines. And turn on echo. You need to see what the CMD sees. Then it becomes obvious. Your use of % is not right. There may be other problems in your code, but this line is wrong (you don't use percent signs around the variable name on the left side of a SET statement) so your variable %prof_name_1% will be undefined (blank) which is the PROBLEM you asked about. Code: [Select]set /p %prof_name_1%=Profile name: Examples: set temperature=30 (right) set %temperature%=30 (wrong) Like Geek says, learn to debug. You could have found this yourself. Quote from: Geek-9pm on December 22, 2015, 10:37:52 PM Somme one could tell you, but you ought to learn now to debug. couldn't you just make it automatically add the address so that you don't have to type it? for example for /f "delims=: tokens=2" %%a in ('ipconfig ^| findstr /R /C:"IPv4 Address"') do (set tempip=%%a) set tempip=%tempip: =% set ip_addr = %tempip% |
|