We are trying to populate a data grid with information from our terminal server sessions using a batch file to populate our data grid. We are using the QWINSTA command in a batch file and have two version. The first version we tried is
This returns an output like this. The issue is that we only need the USERNAME and ID btu each row is one single string.
The first code works and it populated the data grid but with a single string and we are trying to split it into 5 columns.
The second string return just the user name and session ID which is what we need for our application. It also puts a comma between the two variables which we need. However this fails to populate the data grid.
The command above returns
We hope someone can shed some light on what we may be doing wrong or if there is a better way to go about this.
Thanks
RJL
Code:
'qwinsta /server:ILSRF01
This returns an output like this. The issue is that we only need the USERNAME and ID btu each row is one single string.
Code:
SESSIONNAME USERNAME ID STATE TYPE
rdp-tcp#4 mmoore 4 Active rdpwd
rdp-tcp#24 ifranco 22 Active rdpwd
rdp-tcp#39 mlopez 28 Active rdpwd
The first code works and it populated the data grid but with a single string and we are trying to split it into 5 columns.
The second string return just the user name and session ID which is what we need for our application. It also puts a comma between the two variables which we need. However this fails to populate the data grid.
Code:
for /F "tokens=1,2,3" %i in ('qwinsta /server:ILSRF01 ^| findstr "Active"')do @echo %i | find /v "#" | find /v "console" || echo %j,%k,
The command above returns
Code:
mmoore 4
ifranco 22
mlopez 28
We hope someone can shed some light on what we may be doing wrong or if there is a better way to go about this.
Thanks
RJL