title: How to run a batch file for every user returned in list by command net user?
body: <p>My goal is to make a universal code which loops through all user account names in a computer and sends the output to a batch file. The "net user" command outputs a list of users but I want to assign each user name to an argument. So I should use the <code>for /f</code> command to do it. This may look easy, but remember user names may include spaces at any place: at the beginning, at the end or in the middle, Also, it's possible to find 2 consecutive spaces</p>
  
  <p>Hint 1: The maximum length of a user name is 20 characters<br>
  Hint 2: The loops needs to iterate through wrong user names so it needs to check if they're valid. The command <code>net user "uName"</code> sets <code>%ErrorLevel%</code> to 0 if the user name "uName" (for example) is valid.</p>
  
  <p>If there's no way possible, maybe a VBScript could start the batch file with each of the user account names.</p>
  
  <p><strong>Edit:</strong> I finally made my own code, but it takes about 5 seconds for only 15 accounts.</p>
  
  <p>I would like a better solution, maybe with another programming language.</p>
  
  <pre><code>setlocal EnableDelayedExpansion
  For /f "skip=4 delims=" %%I in ('net user') do (
      Set "Line=%%I"
      If not "!Line:~-1,1!" == "." for %%I in (0,25,50) do (
          Set "Name=!Line:~%%I,20!"
          Call :setName
      )
  )
  
  Set Name=
  :setName
  If not "!Name!" == "" (
      Net user "!Name!" &amp;&amp; %~dp0Test.bat "!Name!"
      If not "!Name:~-1,1!" == " " goto:eof
      Set "Name=!Name:~0,-1!"
      Goto setName
  )
  
  endlocal
  </code></pre>