Freelancer: sergreader
Del:
Anmeld Indlæg

Some abstract code...

Hello CH! I don't know at 100 percent but probably you should use AKA batch file and I've read source is https://en.wikibooks.org/wiki/Windows_Batch_Scripting#CALL and I've got next code: echo off set myusername=serg rem tokens=4 is parameter called status FOR /F "tokens=4" %%I IN ('query session %myusername%') DO ( REM A block of code for comparison with word Active and if it is then run any process else exit /b REM It's not good to compare with %%I=='Active' might be better findstr or find IF %%I=='Active' (call mybatch.bat) ELSE (exit /b) )

Konkurrenceindlæg #3 for Windows SHORT One-Liner Script CONTEST can use native versions of gawk sed cut etc and/or perl or dos batch etc, Systems Admin SysAdmin contest

Offentlig Præciserings Opslagstavle

  • jvirt
    Konkurrenceafholder
    • 1 måned siden

    echo off && for /F "tokens=4 usebackq" %i IN (`query session myusername`) DO ( IF NOT %i=='Active' (echo NO_ONE_ELSE_IS_ACTIVE) ELSE (echo YES_OTHERS_ARE_ACTIVE))

    • 1 måned siden
  • jvirt
    Konkurrenceafholder
    • 1 måned siden

    I cleaned it up a bit for command line usage as i required and as you can see your code is nice and clean and could have won if it was a complete solution but it only checks for one username instead of checking if "ANY" other username is active "EXCEPT" myusername

    • 1 måned siden
  • jvirt
    Konkurrenceafholder
    • 1 måned siden

    basically you would need to iterate through and check "all" of the active sessions to make sure that there are no other active sessions "except" myusername

    • 1 måned siden
  • jvirt
    Konkurrenceafholder
    • 1 måned siden

    it is a good start but not sure you understood that i need to know if "Anyone" else was active or not

    • 1 måned siden