Currently I'm logged in as User1 and User2 is disconnected.
When I run the script this is the results I'm getting:
Code: Select all
USER1 is logged on
USER1 is not added
USER2 is logged on
USER2 is not added
PROFILE[0]=USER2
PROFILE[10]=USER1
PROFILE[11]=USER3
PROFILE[1]=USER4
PROFILE[2]=USER5
PROFILE[3]=USER6
PROFILE[4]=USER7
PROFILE[5]=USER3
PROFILE[6]=USER4
PROFILE[7]=USER5
PROFILE[8]=USER6
PROFILE[9]=USER7
USER1 and USER2 gets added to the list, which is correct by the logic in the script, but not the desired result.
I want the results to be without duplicates of users not logged in like:
Code: Select all
PROFILE[0]=USER3
PROFILE[1]=USER4
PROFILE[2]=USER5
PROFILE[3]=USER6
PROFILE[4]=USER7
So in essence, whoever is logged in will not be on the final list of users currently not logged in the computer.
Aacini wrote:I am afraid I don't understand what exactly you are trying to do, but certainly is not "comparing arrays".
Perhaps you want to know "which elements appear in one array, but not in another". If so, then you may use this method:
Code: Select all
REM POPULATE THE ARRAY FROM 'QUERY USER'
FOR /F "SKIP=1 TOKENS=1 DELIMS=> " %%a IN ('QUERY USER') DO (
ECHO %%a is logged on
SET "PROFILE[%%a]=1"
)
REM REMOVE THE ELEMENTS FROM THE OTHER METHOD
FOR /F %%c IN ('DIR /B C:\Users') DO (
SET "REMOVETHIS=YES"
IF %%c NEQ Public IF %%c NEQ NTUSER.DAT IF "%%~c" NEQ "%%~a" SET "REMOVETHIS=NO"
IF !REMOVETHIS! EQU YES (
SET "PROFILE[%%~c]="
ECHO %%c is not added
)
)
SET PROFILE[
I actually wanted the reverse of that. Output of who is not logged in based on who is already logged in.