You are not logged in.

#1 05 Dec 2016 15:29

ImAhNoBoDy
Member
Registered: 29 Dec 2015
Posts: 12

Comparing Arrays

I'm wondering how do you compare the results from one array to another? I'm trying not list users that are not logged in at the moment and then put the results in an array.


@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "a=0"
SET "b=0"

FOR /F "SKIP=1 TOKENS=1 DELIMS=> " %%a IN ('QUERY USER') DO (ECHO %%a is logged on
FOR /F %%c IN ('DIR /B C:\Users') DO (IF %%c NEQ Public IF %%c NEQ NTUSER.DAT IF "%%~c" NEQ "%%~a" SET PROFILE[!b!]=%%c& SET /A "b+=1" ELSE (ECHO %%c is not added))
SET PROFILE[

I got the idea to put in %%~a from http://stackoverflow.com/questions/2295 … two-arrays, but it doesn't seem to be working. Anyone have any ideas?

Offline

#2 15 Dec 2016 18:12

RG
Member
From: Minnesota
Registered: 18 Feb 2010
Posts: 362

Re: Comparing Arrays

1. IF will only parse numbers when NEQ is used https://ss64.com/nt/if.html
2. You are missing a set of parens
3. You should quote values on both sides of ==

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "a=0"
SET "b=0"
 
FOR /F "SKIP=1 TOKENS=1 DELIMS=> " %%a IN ('QUERY USER') DO (
   ECHO %%a is logged on
   FOR /F %%c IN ('DIR /B C:\Users') DO (IF /I NOT "%%c"=="Public" IF /I NOT "%%c"=="NTUSER.DAT" IF NOT "%%~c"=="%%~a" (SET PROFILE[!b!]=%%c& SET /A "b+=1") ELSE (ECHO %%c is not added)
   )
)
SET PROFILE[

Windows Shell Scripting and InstallShield

Offline

Board footer

Powered by