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

Author Topic: Batch File - Combination of WMIC and NET USE to gather Local User Properties  (Read 6880 times)

0 Members and 1 Guest are viewing this topic.

tomlancaster

    Topic Starter


    Starter

    • Experience: Beginner
    • OS: Windows 7
    Hello, I am trying to output the local user accounts and their properties by using WMIC queries to get a list of Local accounts and then run the NET USE command against the account name for the properties. However, the LocalAccounts.txt with the user account names in is not been read by the FOR command.

    The weird thing is if I create my own text file called LocalAccounts.txt with the same data it works. It just doesn't seem to like what is generated from the WMIC command..?

    Can someone help solve?

    Thanks
    Tom

    Code: [Select]
    @ECHO OFF
    WMIC PATH WIN32_USERACCOUNT WHERE LOCALACCOUNT=TRUE GET Name>"%~dp0LocalAccounts.txt"
    FOR /f "usebackq delims=|" %%a IN ("%~dp0LocalAccounts.txt") DO (

        CALL :USER_INFO %%a

    )
    IF EXIST "%~dp0LocalAccounts.txt" DEL /F "%~dp0LocalAccounts.txt"
    GOTO :EOF
    :USER_INFO
    NET USER %1
    ECHO.

    briandams



      Beginner

      Thanked: 2
      • Experience: Guru
      • OS: Unknown
      try this

      Code: [Select]
      for /F .... ( 'WMIC PATH WIN32_USERACCOUNT WHERE LOCALACCOUNT=TRUE get /all /format:csv' ) do (
         ...
      )

      use delims as ","

      Ashtonashlee0



        Newbie

        • Experience: Beginner
        • OS: Windows 7
        This can be called 'string substitution'. Of course you can do that in Notepad, but not from the command line. SED runs from a command and can be inside batch file. When done, SED goes back to the batch file.