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

Author Topic: Batch file to change log on account/password for multiple services  (Read 10012 times)

0 Members and 1 Guest are viewing this topic.

MSGFREEBIRD

    Topic Starter


    Starter

    • Experience: Beginner
    • OS: Windows 7
    I found a reply to a post here by Raven19528 http://www.computerhope.com/forum/index.php/topic,125683.0/prev_next,prev.html#new.  I copied his script modified it for my needs.  The problem I am having is that when I run the batch file it prompts for the user and password but then I get a syntax error and the window closes.  The services do not get changed.  If I take and run an individual line from the file it changes the service successfully.  Can someone look at my file contents and tell me what I am doing wrong? I have changed the name of the services name for this post to Med1-21.

    Any help would be appreciated Thanks
    Gregg

    *********************************
    @echo off
    :username
    cls
    echo.
    echo Enter the UserName
    set /p user={User}
    cls
    echo.
    echo %user%
    echo.
    echo Is this correct?
    set /p yn1={y/n}
    if /i "%yn1%"=="y" goto password
    goto username
    :password
    cls
    echo.
    echo Enter the password
    set /p pass={Password}
    cls
    echo.
    echo %pass%
    echo.
    echo Is this correct?
    set /p yn2={y/n}
    if /i %yn2%"=="y" goto services
    goto password
    :services
    sc config "Med1" obj= "%user%" Password= "%pass%"
    sc config "Med2" obj= "%user%" Password= "%pass%"
    sc config "Med3" obj= "%user%" Password= "%pass%"
    sc config "Med4" obj= "%user%" Password= "%pass%"
    sc config "Med6" obj= "%user%" Password= "%pass%"
    sc config "Med7" obj= "%user%" Password= "%pass%"
    sc config "Med8" obj= "%user%" Password= "%pass%"
    sc config "Med9" obj= "%user%" Password= "%pass%"
    sc config "Med10" obj= "%user%" Password= "%pass%"
    sc config "Med11" obj= "%user%" Password= "%pass%"
    sc config "Med12" obj= "%user%" Password= "%pass%"
    sc config "Med13" obj= "%user%" Password= "%pass%"
    sc config "Med14" obj= "%user%" Password= "%pass%"
    sc config "Med15" obj= "%user%" Password= "%pass%"
    sc config "Med16" obj= "%user%" Password= "%pass%"
    sc config "Med17" obj= "%user%" Password= "%pass%"
    sc config "Med18" obj= "%user%" Password= "%pass%"
    sc config "Med19" obj= "%user%" Password= "%pass%"
    sc config "Med20" obj= "%user%" Password= "%pass%"
    sc config "Med21" obj= "%user%" Password= "%pass%"

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Re: Batch file to change log on account/password for multiple services
    « Reply #1 on: April 26, 2014, 10:32:52 AM »
    Open a cmd window and type the batch file name.  The error message will stay on the screen and you can tell us what it says.

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Re: Batch file to change log on account/password for multiple services
    « Reply #2 on: April 26, 2014, 10:43:25 AM »
    Here's a simpler method of doing the same thing.  Add the extra services and remove the pause once it is debugged.

    EDITED:

    Code: [Select]
    @echo off
    :loop
    cls
    set "user="
    set "pass="
    set /p "user=Enter the UserName: "
    set /p "pass=Enter the Password: "
    echo(
    echo Username:"%user%"  Password:"%pass%"
    echo(
    set "var="
    set /p "var=Correct? Enter n for no or just press enter to continue: "
    if defined var goto :loop

    for %%a in ("Med1" "Med2" "Med3" "Med4" "Med5" "Med6" "Med7" "Med8" "Med9") do (
       sc config %%a obj= "%user%" Password= "%pass%"
    )
    pause
    « Last Edit: April 26, 2014, 10:59:26 AM by foxidrive »

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Re: Batch file to change log on account/password for multiple services
    « Reply #3 on: April 26, 2014, 10:50:51 AM »
    FWIW your error is in this line and it is missing a double quote:

    Code: [Select]
    if /i %yn2%"=="y" goto services
    It should be:

    Code: [Select]
    if /i "%yn2%"=="y" goto services

    MSGFREEBIRD

      Topic Starter


      Starter

      • Experience: Beginner
      • OS: Windows 7
      Re: Batch file to change log on account/password for multiple services
      « Reply #4 on: April 26, 2014, 10:56:29 AM »
      Thank You Foxdrive, fixing the double quote worked.  THANK YOU. I looked and looked and I missed that one.

      foxidrive



        Specialist
      • Thanked: 268
      • Experience: Experienced
      • OS: Windows 8
      Re: Batch file to change log on account/password for multiple services
      « Reply #5 on: April 26, 2014, 11:01:43 AM »
      You're welcome. :)

      I edited the simpler version above too if you want to test it.

      MSGFREEBIRD

        Topic Starter


        Starter

        • Experience: Beginner
        • OS: Windows 7
        Re: Batch file to change log on account/password for multiple services
        « Reply #6 on: April 26, 2014, 11:20:20 AM »
        Yes I tried your simpler version and I think I will use it instead.  It has a much cleaner look to the way it runs.  Thank you again.

        MSGFREEBIRD

          Topic Starter


          Starter

          • Experience: Beginner
          • OS: Windows 7
          Re: Batch file to change log on account/password for multiple services
          « Reply #7 on: April 28, 2014, 08:41:15 AM »
          Foxidrive

          I have another question if you do not mind.  How could I modify your modified script to enable it to change the services on multiple servers and workstations.  Is there an easy way to do that?

          Thanks
          Gregg

          foxidrive



            Specialist
          • Thanked: 268
          • Experience: Experienced
          • OS: Windows 8
          Re: Batch file to change log on account/password for multiple services
          « Reply #8 on: April 28, 2014, 09:06:02 AM »
          Gregg, there are permissions involved, maybe PSEXEC or Wmic will be useful, but I have no workplace experience in multiple LANS and servers so can't offer much in that area.

          Someone else may help there.

          Squashman



            Specialist
          • Thanked: 134
          • Experience: Experienced
          • OS: Other
          Re: Batch file to change log on account/password for multiple services
          « Reply #9 on: April 28, 2014, 10:03:28 AM »
          Read the Help for the SC command and you will quickly realize that there is an option to specify the Server.