Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Please help me with a batch file  (Read 3473 times)

0 Members and 1 Guest are viewing this topic.

Inforcer25

    Topic Starter


    Starter

    • Experience: Familiar
    • OS: Windows 7
    Please help me with a batch file
    « on: December 22, 2015, 08:05:18 PM »
    Ok so it does what it is supposed to but i am not going to give the full code of everything

    What is wrong is is that everything works fine but it doesnt give the batch file a name Eg. "test.bat" all it does is make it ".bat"

    here is the code i use: (Hope you can help)

    Code: [Select]
    :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

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Please help me with a batch file
    « Reply #1 on: December 22, 2015, 08:25:25 PM »
    What is this?
    Quote
    )>C:\IP_Changer\Profiles\%prof_name_1%.bat

    You need to explain what you intend to do.
     That way you get more help quicker.  :)

    Inforcer25

      Topic Starter


      Starter

      • Experience: Familiar
      • OS: Windows 7
      Re: Please help me with a batch file
      « Reply #2 on: December 22, 2015, 10:12:21 PM »
      What is this?
      You need to explain what you intend to do.
       That way you get more help quicker.  :)

      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 =======================================================================================================================================

      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: Please help me with a batch file
      « Reply #3 on: December 22, 2015, 10:37:52 PM »
      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.


      Salmon Trout

      • Guest
      Re: Please help me with a batch file
      « Reply #4 on: December 23, 2015, 12:48:58 AM »
      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.



      zask



        Intermediate

        • Experience: Experienced
        • OS: Other
        Re: Please help me with a batch file
        « Reply #5 on: December 29, 2015, 10:44:37 AM »
        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.

        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%