Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am redesigning an older batch script to redirect the output to HTML instead of text. I have converted most of the script, but have one section that is giving me problem.
My problem is how to redirect the output from the command below and add line breaks (returns) for each entry:
net share | FIND /V /I "The command completed successfully"
I have tried the following but it fails to produce the desired results:
net.exe share | FIND /V /I "The command completed successfully" ^<br^>
Some of my other queries look like the example below and they work fine, because they are only producing one-line outputs:
FOR /F "delims=" %%a in ('systeminfo 2^>nul^|FIND /I "Host Name:"') do echo %%a ^<br^>
TIA for any support

Because your need the <br> at the end of each line you going to need to run all of the commands with multiple lines of output through a for /f loop.
for /f "delims=" %%a in ('net share^|FIND /V /I "The command completed successfully"') do ( echo %%a ^<br^> )The other alternative it to use <pre> tags so that the line breaks will work without using <br>

Thanks for the reply. I looked into using
and decided to go that route. The interesting thing about usingis that it preserves basic formatting, but adds an extra line between all the outputted entries, which is ok, because it helps with readability. I had to add some span tags to adjust the font-size and alignment.I have tried unsuccessfully to add
tags to the following code snippet. Any suggestions?for /f "tokens=*" %%a in ('fsutil fsinfo drives^|find /v ""') do (
set dr=%%a
call set driveList=%%driveList%% %%dr:~-3%%
)
for %%a in (%driveList%) do fsutil fsinfo drivetype %%a
TIA for any reply.

The problem with fsutil is that it outputs in nonstandard formats. Sometimes you can utilize others just screw things up. For example "fsutil fsinfo drives" uses nul(hex 00) instead of spaces(hex 20), find interprets it as unicode text(in unicode ansi is accompanied with a second byte that is 00).
It also seems to output line brakes strangely, I have seen 0d0d0a and 0d20200d0a instead of plain old 0d0a.
Any way I have tried but failed, anyway I have to go to work now here's what I got up to:
@ECHO OFF for /f "tokens=*" %%a in ('fsutil fsinfo drives^|find /v ""') do ( set dr=%%a call set driveList=%%driveList%% "%%dr:~-3%%" ) for %%a in (%driveList%) do @( for /f "tokens=1,2,3*" %%b in ('fsutil fsinfo drivetype %%~a') do ( echo %%b %%c %%d Drive ^<br^> ) )Getting rid of the "drive" seems to get rid or the extra carrage return (0d).

This is the last item that I am trying to fix. The code below output the requested information, but fails to separate the accounts. Any idea on how to add this separations between accounts?
FOR /F "skip=4 tokens=*" %%a IN ('net.exe user ^| FIND /V /I "The command completed successfully"') DO CALL :ParseUsers %%a
GOTO:EOF:ParseUsers
FOR %%? IN (%*) DO CALL :ChkAcc %%?
GOTO:EOF:: This is the section that does not produce the
:: desired separation.
:ChkAcc
FOR /F "tokens=* delims=" %%f IN ('net.exe user "%*" 2^>nul ^| FIND /V /I "The command completed successfully"') do (echo ^<pre^> %%f ^</pre^>)
GOTO:EOF

Yep simply echo <br> a couple of times after each account. I also
changed the way the <pre> tags were entered because it looked
ugly in firefox, you can easily change it back:@ECHO OFF FOR /F "skip=4 delims=" %%a IN ('net.exe user ^| FIND /V /I "The command completed successfully"') DO CALL :ParseUsers %%a goto :eof :ParseUsers FOR %%? IN (%*) DO CALL :ChkAcc %%? GOTO:EOF :: This is the section that does not produce the :: desired separation. :ChkAcc echo ^<pre^> FOR /F "delims=" %%f IN ('net.exe user "%*" 2^>nul ^| FIND /V /I "The command completed successfully"') do echo %%f echo ^</pre^> echo ^<br^> echo ^<br^> GOTO:EOF

Thanks, I did not even think about trying to add an echo before the HTML code tags. The code works great. I need to do some research to fix the bug within this code that throws the error when an account name contain a space.
This account name works: myAccountName
This account name fails: my Account NameIn manual testing, I was able to fix it by wrapping the account name in " ".
Thanks again.

I'm not sure it this will be any help to you or not;
it won't pick up any system accounts...@ECHO OFF for /f "skip=4 delims=" %%a in ('2^>nul reg query hku') do ( for /f "tokens=4* skip=4" %%b in ('2^>nul reg query "%%a\Software\Microsoft\Windows\CurrentVersion\Explorer" /v "logon user name"') do ( echo %%c ) )Edit:
I just realized this will only work to find the current user name, not all of them.............

Within the code is there a method to encapsulate the account name variables with quotation marks?

I had a look into it and it seems that the "net user" command is
more consistent than it first appears.Windows only seems to allow account names that contain up to a
maximum of 20 characters, not allowing leading or trailing spaces.The "net user" command displays the username padded to 20
characters with trailing spaces along with 5 additional
spaces to separate entries.I was able to get it to work with spaces and ampersands,
it should presumably work with any other allowed characters.....I was using a test account called "test & 2"
@ECHO OFF for /f "skip=4 delims=" %%a in ('net user^|find /v /i "The command completed"') do ( set line=%%a call :linesub ) goto :eof :linesub if not defined line goto :eof if "%line: =%"=="" goto :eof set "uname=%line:~0,20%" set "line=%line:~25%" :depad if "%uname:~-1%"==" " ( set "uname=%uname:~0,-1%" goto depad ) echo ^<pre^> FOR /F "delims=" %%f IN ('net.exe user "%uname%" 2^>nul ^| FIND /V /I "The command completed successfully"') do echo %%f echo ^</pre^> echo ^<br^> echo ^<br^> GOTO linesub

Thanks again. My old batch file has been GREATLY improved with your assistance!!
TODO items to finish:
1. basic error handling (if not exist, if errorlevel 1)
2. creation and destruction of %temp% files in %CD%THANKS AGAIN.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |