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

Author Topic: batch file help please  (Read 5575 times)

0 Members and 1 Guest are viewing this topic.

popthree

    Topic Starter


    Starter

    batch file help please
    « on: September 04, 2008, 12:44:06 PM »
    i want to write a batch file that first runs

    NET LOCALGROUP

    then takes the output from that and runs

    NET LOCALGROUP 'administratirs'
    NET LOCALGROUP 'guests'
    NET LOCALGROUP ...
    ...
    and so on... a separate NET LOCALGROUP command for each of the groups that was output from the first command.  any idea how i can accomplish this ?  i'd really like to get it done with a single script...rather than having the first command output to a file and then parse that file..but if it must be done with 2 separate scripts then it must.  can anyone help ?

    diablo416



      Hopeful
      Re: batch file help please
      « Reply #1 on: September 04, 2008, 01:08:03 PM »
      for /f "tokens=1,2*" %a in ('NET LOCALGROUP ^|find /I /V "the"') do echo %a

      the above will set the user groups into %a ,

      for /f "tokens=1,2*" %a in ('NET LOCALGROUP ^|find /I /V "the"') do NET LOCALGROUP '%a'

      using this in a batch file remember to add an additional percentile symbol , example

      for /f "tokens=1,2*" %%a in ('NET LOCALGROUP ^|find /I /V "the"') do NET LOCALGROUP '%%a'

      popthree

        Topic Starter


        Starter

        Re: batch file help please
        « Reply #2 on: September 11, 2008, 01:01:51 PM »
        thank you for the reply.

        when i run this command
        for /f "tokens=1,2*" %%a in ('NET LOCALGROUP ^|find /I /V "the"') do NET LOCALGROUP '%%a'

        here is the output i am getting .... seems to dislike group names with spaces in them.. and check the administrators group.. it has a * pended to the front of it.

        D:\Documents and Settings\user1>"D:\Documents and Settings\user1\Desktop\123.
        at"

        D:\Documents and Settings\user1>for /F "tokens=1,2*" %a in ('NET LOCALGROUP |f
        nd /I /V "the"') do NET LOCALGROUP '%a'

        D:\Documents and Settings\user1>NET LOCALGROUP 'Aliases'
        System error 1376 has occurred.

        The specified local group does not exist.


        D:\Documents and Settings\user1>NET LOCALGROUP '------------------------------
        ------------------------------------------------'
        System error 1376 has occurred.

        The specified local group does not exist.


        D:\Documents and Settings\user1>NET LOCALGROUP '*Administrators'
        The syntax of this command is:


        NET LOCALGROUP
        [groupname [/COMMENT:"text"]] [/DOMAIN]
                      groupname {/ADD [/COMMENT:"text"] | /DELETE}  [/DOMAIN]
                      groupname name [...] {/ADD | /DELETE} [/DOMAIN]


        D:\Documents and Settings\user1>NET LOCALGROUP '*Backup'
        The syntax of this command is:


        NET LOCALGROUP
        [groupname [/COMMENT:"text"]] [/DOMAIN]
                      groupname {/ADD [/COMMENT:"text"] | /DELETE}  [/DOMAIN]
                      groupname name [...] {/ADD | /DELETE} [/DOMAIN]


        D:\Documents and Settings\user1>NET LOCALGROUP '*Debugger'
        The syntax of this command is:


        NET LOCALGROUP
        [groupname [/COMMENT:"text"]] [/DOMAIN]
                      groupname {/ADD [/COMMENT:"text"] | /DELETE}  [/DOMAIN]
                      groupname name [...] {/ADD | /DELETE} [/DOMAIN]


        D:\Documents and Settings\user1>NET LOCALGROUP '*Guests'
        The syntax of this command is:


        NET LOCALGROUP
        [groupname [/COMMENT:"text"]] [/DOMAIN]
                      groupname {/ADD [/COMMENT:"text"] | /DELETE}  [/DOMAIN]
                      groupname name [...] {/ADD | /DELETE} [/DOMAIN]


        D:\Documents and Settings\user1>NET LOCALGROUP '*HelpServicesGroup'
        The syntax of this command is:


        NET LOCALGROUP
        [groupname [/COMMENT:"text"]] [/DOMAIN]
                      groupname {/ADD [/COMMENT:"text"] | /DELETE}  [/DOMAIN]
                      groupname name [...] {/ADD | /DELETE} [/DOMAIN]


        D:\Documents and Settings\user1>NET LOCALGROUP '*Network'
        The syntax of this command is:


        NET LOCALGROUP
        [groupname [/COMMENT:"text"]] [/DOMAIN]
                      groupname {/ADD [/COMMENT:"text"] | /DELETE}  [/DOMAIN]
                      groupname name [...] {/ADD | /DELETE} [/DOMAIN]


        D:\Documents and Settings\user1>NET LOCALGROUP '*Offer'
        The syntax of this command is:


        NET LOCALGROUP
        [groupname [/COMMENT:"text"]] [/DOMAIN]
                      groupname {/ADD [/COMMENT:"text"] | /DELETE}  [/DOMAIN]
                      groupname name [...] {/ADD | /DELETE} [/DOMAIN]


        D:\Documents and Settings\user1>NET LOCALGROUP '*Power'
        The syntax of this command is:


        NET LOCALGROUP
        [groupname [/COMMENT:"text"]] [/DOMAIN]
                      groupname {/ADD [/COMMENT:"text"] | /DELETE}  [/DOMAIN]
                      groupname name [...] {/ADD | /DELETE} [/DOMAIN]


        D:\Documents and Settings\user1>NET LOCALGROUP '*Remote'
        The syntax of this command is:


        NET LOCALGROUP
        [groupname [/COMMENT:"text"]] [/DOMAIN]
                      groupname {/ADD [/COMMENT:"text"] | /DELETE}  [/DOMAIN]
                      groupname name [...] {/ADD | /DELETE} [/DOMAIN]


        D:\Documents and Settings\user1>NET LOCALGROUP '*Replicator'
        The syntax of this command is:


        NET LOCALGROUP
        [groupname [/COMMENT:"text"]] [/DOMAIN]
                      groupname {/ADD [/COMMENT:"text"] | /DELETE}  [/DOMAIN]
                      groupname name [...] {/ADD | /DELETE} [/DOMAIN]


        D:\Documents and Settings\user1>NET LOCALGROUP '*Users'
        The syntax of this command is:


        NET LOCALGROUP
        [groupname [/COMMENT:"text"]] [/DOMAIN]
                      groupname {/ADD [/COMMENT:"text"] | /DELETE}  [/DOMAIN]
                      groupname name [...] {/ADD | /DELETE} [/DOMAIN]

        D:\Documents and Settings\user1>^A






        Sidewinder



          Guru

          Thanked: 139
        • Experience: Familiar
        • OS: Windows 10
        Re: batch file help please
        « Reply #3 on: September 11, 2008, 02:02:12 PM »
        I'm confused why you would look for lines not containing the word the. Knowing that each line you need is pre-pended with a star is an important piece of information.

        Code: [Select]
        @echo off
        setlocal enabledelayedexpansion
        for /f "tokens=1 delims=" %%a in ('net localgroup ^| find "*"') do (
        set lg=%%a
        set lg=!lg:~1!
        net localgroup !lg!
        )

         8)
        The true sign of intelligence is not knowledge but imagination.

        -- Albert Einstein

        popthree

          Topic Starter


          Starter

          Re: batch file help please
          « Reply #4 on: September 11, 2008, 02:40:54 PM »
          hi, thank you for replying.

          i think that is very close.  is there a way to make the group names be in " quotes "  ?

          it doesn't seem to work on groups  like   Backup Operators   or Power Users   i'm guessing because they are not in quotes.

          to successfully return a list of users from the Power Users group the command would be

          Net LocalGroup "Power Users"

          Sidewinder



            Guru

            Thanked: 139
          • Experience: Familiar
          • OS: Windows 10
          Re: batch file help please
          « Reply #5 on: September 11, 2008, 02:48:04 PM »
          If you need quotes, you can add them to the final set command:

          Code: [Select]
          @echo off
          setlocal enabledelayedexpansion
          for /f "tokens=1 delims=" %%a in ('net localgroup ^| find "*"') do (
          set lg=%%a
          set lg="!lg:~1!"
          net localgroup !lg!
          )

           8)
          The true sign of intelligence is not knowledge but imagination.

          -- Albert Einstein

          popthree

            Topic Starter


            Starter

            Re: batch file help please
            « Reply #6 on: September 11, 2008, 03:07:40 PM »
            thank you.  :)