61
General Software Discussion / Re: Help with Windows batch script
« on: May 06, 2015, 12:13 AM »
Wow, I like how compact your example is! :up:
I managed to modify my script, using an array of users and a FOR loop, somewhat similar to yours.
Output from the QUERY USER /SERVER: looks the same as query on localhost. Here's a sample (names changed, of course):
After looking at your code a bit more, i think it would have to be modified a bit. I think you'd need to create a file of the users that should NOT be logged off, then have a FOR loop for each server, and have a FOR loop extracting each user currently logged on that server. Then you could use the FIND command to see if the current login ID is in the file to be ignored, and if it's not, then you'd issue the LOGOFF command. Unless I totally missed your example?
Bottom line, I finally did get my script to work.
Thanks for your reply!
I managed to modify my script, using an array of users and a FOR loop, somewhat similar to yours.
Output from the QUERY USER /SERVER: looks the same as query on localhost. Here's a sample (names changed, of course):
Code: Text [Select]
- USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME
- ablebz 2 Disc 4:25 5/5/2015 5:33 AM
- wertala 4 Disc 2:57 5/5/2015 10:21 AM
- trowe801 rdp-tcp#40 7 Active 5:18 5/5/2015 10:49 AM
- aspensma 8 Disc 4:17 5/5/2015 3:18 PM
After looking at your code a bit more, i think it would have to be modified a bit. I think you'd need to create a file of the users that should NOT be logged off, then have a FOR loop for each server, and have a FOR loop extracting each user currently logged on that server. Then you could use the FIND command to see if the current login ID is in the file to be ignored, and if it's not, then you'd issue the LOGOFF command. Unless I totally missed your example?
Bottom line, I finally did get my script to work.
Thanks for your reply!