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

Author Topic: Script created to change log on account/password services help  (Read 7063 times)

0 Members and 1 Guest are viewing this topic.

animalkrack3r

    Topic Starter


    Greenhorn

    • Experience: Beginner
    • OS: Unknown
    Script created to change log on account/password services help
    « on: November 30, 2011, 08:43:54 AM »





    i'm trying to write a script to stop a group of services , change the Log on name / set password for each service and then start then back up. For this examples I used the BITS Service in windows .....
    What I have so far are as follows:

    I'm not sure about much of this and any help would grateul!

    sc query state= all | grep "SERVICE_NAME: BITS" > C:\sc.out


    -----------------Start Services Change Script-------------------

    sc config <BITS> obj= TeeCee etc.
    sc stop . . .
    sc start . . .



    C:\>sc stop

    sc <server> stop [BITS]

    C:\>sc start

    sc <server> start [BITS] <arg1> <arg2> ...

    C:\>sc config

    SYNTAX:
    sc <server> config [BITS]
    DisplayName= <TESTUSER>
    password= <password>...


    CONFIG OPTIONS:
    NOTE: The option name includes the equal sign.
    type= <own|share|interact|kernel|filesys|rec|adapt>
    start= <boot|system|auto|demand|disabled>
    error= <normal|severe|critical|ignore>
    binPath= <BinaryPathName>
    group= <LoadOrderGroup>
    tag= <yes|no>
    depend= <Dependencies(separated by / (forward slash))>
    obj= <AccountName|ObjectName>
    DisplayName= <display name>
    password= <password>


    ---------------End--------------------------------------

     


    Raven19528



      Hopeful
    • Thanked: 30
      • Computer: Specs
      • Experience: Experienced
      • OS: Windows 7
      Re: Script created to change log on account/password services help
      « Reply #1 on: November 30, 2011, 09:24:08 AM »
      It would seem you already have your code, you just need to put it together.

      Code: [Select]
      sc <server> stop [BITS]
      sc <server> config [BITS] obj=TeeCee DisplayName=<TESTUSER> Password=password
      sc <server> start [BITS]

      I don't use batch for a lot of network things, and this is untested.
      "All things that are
      Are with more spirit chased than enjoy'd" -Shakespeare

      animalkrack3r

        Topic Starter


        Greenhorn

        • Experience: Beginner
        • OS: Unknown
        Re: Script created to change log on account/password services help
        « Reply #2 on: November 30, 2011, 10:23:30 AM »
        What would you suggest? I am trying to create something to run for a group of services...


        Its about 8 services that I always changed per clients server to the correct domain\Log On and Password save it and restart services
        but i have to do this for each of them everytime on tons of different servers so i was trying to find a better way..

        Thanks for the help !!!!!!

        animalkrack3r

          Topic Starter


          Greenhorn

          • Experience: Beginner
          • OS: Unknown
          Re: Script created to change log on account/password services help
          « Reply #3 on: November 30, 2011, 10:26:01 AM »
          "It would seem you already have your code, you just need to put it together.


          Code: [Select]
          sc <server> stop [BITS]
          sc <server> config [BITS] obj=TeeCee DisplayName=<TESTUSER> Password=password
          sc <server> start [BITS]

          I don't use batch for a lot of network things, and this is untested."

          and yes anything to help me put this together is greatly appriciated!

          Raven19528



            Hopeful
          • Thanked: 30
            • Computer: Specs
            • Experience: Experienced
            • OS: Windows 7
            Re: Script created to change log on account/password services help
            « Reply #4 on: November 30, 2011, 12:46:05 PM »
            Try this batch file. You will need to create a plain text list (in notepad) of servers using a carraige return to seperate them. I.e.


            >>List.txt<<
            server1
            server2
            server3
            etc.


            You will also need to fill in the [service1],[service2] in the below code with the services you are needing to change. Most of this code just allows you to run the batch file and determine the username and password when you run it instead of having to modify the batch every time. If the services tend to change often, you may want to run an embedded "for" loop to help alleviate your need to modify the batch program. Let me know if you would like to see that coded out.

            Code: [Select]
            @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
            for /f "delims=" %%A in (List.txt) do (
              sc %%A stop [service1]
              sc %%A config [service1] obj=TeeCee DisplayName=%user% Password=%pass%
              sc %%A start [service1]
              sc %%A stop [service2]
              sc %%A config [service2] obj=TeeCee DisplayName=%user% Password=%pass%
              sc %%A start [service2]
              ...lather, rinse, repeat...
            )
            "All things that are
            Are with more spirit chased than enjoy'd" -Shakespeare

            animalkrack3r

              Topic Starter


              Greenhorn

              • Experience: Beginner
              • OS: Unknown
              Re: Script created to change log on account/password services help
              « Reply #5 on: November 30, 2011, 04:49:20 PM »
              Thank you kind sir!
              What I have is as follows:

              I created a list.txt and placed it in my root (C) , i'm also not sure what belongs in the <server> field... i'm assuming my computer name , but after running it i'm getting a syntex error

              Thoughts?

              @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
              for /f "delims=" %%A in (List.txt) do (
                sc %%A stop [BITS]
                sc %%A config [BITS] obj=TeeCee DisplayName=%user% Password=%pass%
                sc %%A start [BITS]
                sc %%A stop [BITS]
                sc %%A config [BITS] obj=TeeCee DisplayName=%user% Password=%pass%
                sc %%A start [BITS]
                ...lather, rinse, repeat...
              )

              Raven19528



                Hopeful
              • Thanked: 30
                • Computer: Specs
                • Experience: Experienced
                • OS: Windows 7
                Re: Script created to change log on account/password services help
                « Reply #6 on: November 30, 2011, 05:15:38 PM »
                Code: [Select]
                for /f "delims=" %%A in (List.txt) do (
                  sc %%A stop [BITS]
                  sc %%A config [BITS] obj=TeeCee DisplayName=%user% Password=%pass%
                  sc %%A start [BITS]
                  sc %%A stop [BITS]
                  sc %%A config [BITS] obj=TeeCee DisplayName=%user% Password=%pass%
                  sc %%A start [BITS]
                  ...lather, rinse, repeat...
                )
                *chuckles*

                I love how you used the exact script... you can take out the lather, rinse, repeat line, it was in there so you would know that any additional services you wanted to update would have the same syntax as what you see there.

                The server name needs to be the full computer name of the server. I.e. if you are on a domain, it needs to have the "dot domain name" included. If it is just your computer (or just the computer that it is going to run on), you can actually replace that with a "." and you will accomplish the same thing.
                "All things that are
                Are with more spirit chased than enjoy'd" -Shakespeare

                Squashman



                  Specialist
                • Thanked: 134
                • Experience: Experienced
                • OS: Other
                Re: Script created to change log on account/password services help
                « Reply #7 on: November 30, 2011, 06:48:20 PM »
                If it is the same services that have to be configured on each server then wy not make a text file with the services that need to be configured and create an inner for loop to parse that as well.

                animalkrack3r

                  Topic Starter


                  Greenhorn

                  • Experience: Beginner
                  • OS: Unknown
                  Re: Script created to change log on account/password services help
                  « Reply #8 on: November 30, 2011, 07:56:48 PM »
                  lol excuse my extreme noobness with batch files, thank you very very much Raven!

                  @Squashman, explain ? thanks!