locked
output of the script - syntax prob RRS feed

  • Question

  • Hi,

    I found a script for user logoff...

    ______What we do is, create a scheduled task running as system account. It uses a batch that goes:

    del %temp%\DisconSessions.txt del %temp%\delSessions.txt qwinsta |findstr Disc >%temp%\DisconSessions.txt findstr /v services %temp%\DisconSessions.txt>%temp%\delSessions.txt for /f "tokens=2" %%a in (%temp%\delSessions.txt) do logoff %%a

    _____________

    I created a batch...

    When run for test from cmd (on Win10),nothing happens and I see one % is missing in last line output.

    So, it looks like that:

    for /f "tokens=2" %a in (%temp%\delSessions.txt) do logoff %a

    Is this script for bat? (was not mentioned in the page I found. Or something else?

    thx.


    --- When you hit a wrong note its the next note that makes it good or bad. --- Miles Davis

    Monday, December 17, 2018 3:45 PM

Answers

  • You said that that you tested on Win10, not Win10 Enterprise. My mistake was seeing "Win10" and assuming that my Win10 Home laptop was a valid test machine. My fault.  

    Had you run the commands you should have see something like this:

    C:\Users\Admin>qwinsta
     SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
     services                                    0  Disc
    >console           Admin                     1  Active

    C:\Users\Admin>qwinsta |findstr Disc
     services                                    0  Disc

    C:\Users\Admin>qwinsta |findstr Disc | findstr /v services

    C:\Users\Admin>findstr /?
    Searches for strings in files.
    FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P] [/F:file]
            [/C:string] [/G:file] [/D:dir list] [/A:color attributes] [/OFF[LINE]]
            strings [[drive:][path]filename[ ...]]
      /B         Matches pattern if at the beginning of a line.
      /E         Matches pattern if at the end of a line.
      /L         Uses search strings literally.
      /R         Uses search strings as regular expressions.
      /S         Searches for matching files in the current directory and all
                 subdirectories.
      /I         Specifies that the search is not to be case-sensitive.
      /X         Prints lines that match exactly.
      /V         Prints only lines that do not contain a match.

    The script that you found is intended to log disconnected users off from a terminal server.  That is why I asked: Do you want to logoff disconnected sessions or the current logged on user? You got a negative result because your Win10 Enterprise machine probably only has the user logged on to the desktop. But I will apologize for that in advance  because I have to make some assumptions and they might not be correct. If you found a solution, congrats. I just wanted to explain my thought process. Thanks for hearing me out.   


    • Edited by MotoX80 Tuesday, December 18, 2018 2:55 AM
    • Marked as answer by pob579 Tuesday, December 18, 2018 2:32 PM
    Tuesday, December 18, 2018 2:52 AM

All replies

  • When run for test from cmd (on Win10),nothing happens 

    qwinsta is not a valid Win10 command. It only applies to Windows Server. 

    https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/qwinsta


    Monday, December 17, 2018 4:09 PM
  • Thanks for the answer...

    in the article:

    https://www.experts-exchange.com/questions/28980782/Create-a-scheduled-task-that-would-log-off-users-at-a-certain-time-daily.html

    they talking about applying the script to W7. And it worked... So not only the server (from what I see).

    May be it is W10 ...

    What people can suggest. I urgently need to do something with logoff console session daily on Wind10 machine.


    --- When you hit a wrong note its the next note that makes it good or bad. --- Miles Davis

    Monday, December 17, 2018 5:08 PM
  • It's not correct that the qwinsta command works only in Windows Server.

    But aside from that, this forum is for scripting questions, not script requests.

    Read this first:

    This forum is for scripting questions rather than script requests


    -- Bill Stewart [Bill_Stewart]

    Monday, December 17, 2018 5:54 PM
  • so if qwinsta is not the problem...

    the initial question was for possible error in the existing script, not for script request...

    Dear moderator sorry for arguing :)...

    Please remove this thread... I will address somewhere else.

    Thanks...


    --- When you hit a wrong note its the next note that makes it good or bad. --- Miles Davis

    Monday, December 17, 2018 6:30 PM
  • My mistake.... qwinsta and logoff are distributed with Win10 Pro but not Win10 Home. (And of course I first test on my Home laptop.)

    If you move this thread to an appropriate forum, I will try to help pob579. 

    • Edited by MotoX80 Monday, December 17, 2018 6:58 PM
    Monday, December 17, 2018 6:50 PM
  • wrong statement Mr. Moto...

    I run the thingy on W10 Enterpr... So it is something else.

    But we close discussion on that :)

    I understand, the question violates the rules of this forum.


    --- When you hit a wrong note its the next note that makes it good or bad. --- Miles Davis

    Monday, December 17, 2018 6:57 PM
  • See my other reply, I tested on Win10 Home. My bad. 

    Do you want to logoff disconnected sessions or the current logged on user? 

    Monday, December 17, 2018 7:00 PM
  • and I am saying, I tested on W10 Enterp. and it give negative result that I mentioned in my initial post.

    Found other solution.

    Thanks.


    --- When you hit a wrong note its the next note that makes it good or bad. --- Miles Davis

    Monday, December 17, 2018 7:06 PM
  • You said that that you tested on Win10, not Win10 Enterprise. My mistake was seeing "Win10" and assuming that my Win10 Home laptop was a valid test machine. My fault.  

    Had you run the commands you should have see something like this:

    C:\Users\Admin>qwinsta
     SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
     services                                    0  Disc
    >console           Admin                     1  Active

    C:\Users\Admin>qwinsta |findstr Disc
     services                                    0  Disc

    C:\Users\Admin>qwinsta |findstr Disc | findstr /v services

    C:\Users\Admin>findstr /?
    Searches for strings in files.
    FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P] [/F:file]
            [/C:string] [/G:file] [/D:dir list] [/A:color attributes] [/OFF[LINE]]
            strings [[drive:][path]filename[ ...]]
      /B         Matches pattern if at the beginning of a line.
      /E         Matches pattern if at the end of a line.
      /L         Uses search strings literally.
      /R         Uses search strings as regular expressions.
      /S         Searches for matching files in the current directory and all
                 subdirectories.
      /I         Specifies that the search is not to be case-sensitive.
      /X         Prints lines that match exactly.
      /V         Prints only lines that do not contain a match.

    The script that you found is intended to log disconnected users off from a terminal server.  That is why I asked: Do you want to logoff disconnected sessions or the current logged on user? You got a negative result because your Win10 Enterprise machine probably only has the user logged on to the desktop. But I will apologize for that in advance  because I have to make some assumptions and they might not be correct. If you found a solution, congrats. I just wanted to explain my thought process. Thanks for hearing me out.   


    • Edited by MotoX80 Tuesday, December 18, 2018 2:55 AM
    • Marked as answer by pob579 Tuesday, December 18, 2018 2:32 PM
    Tuesday, December 18, 2018 2:52 AM
  • Thank you very much. I clearly understand what you are saying.

    In my case, yes I tried to logoff logged in user with locked console (by gpo) user...


    --- When you hit a wrong note its the next note that makes it good or bad. --- Miles Davis

    Tuesday, December 18, 2018 2:33 PM