Avatar of OB1Canobie
Flag for United States of America

asked on 

Force users to be logged off using batch file

I currently am trying to write a batch file that will log off all users to a server.  I have read many articles about using psshutdown.exe a freeware utility.  I currently have the script written and I have attached below, however, I don't have something quite right.  I keep getting the message "Syntax ForceLogoff Exceptions".  I believe the that I am closed but can't seem to figure this out.  The article that I used is found at: http://windowsitpro.com/articles/index.cfm?articleid=81912.  Can someone help?
ForceLogoff.bat contains:
@echo off
if {%1}=={} @echo Syntax ForceLogoff Exceptions&goto :EOF
if not exist %1 @echo Syntax ForceLogoff Exceptions - %1 does NOT exist.&goto :EOF
set except=%1
set dom=%USERDOMAIN%
for /f "Tokens=1" %%c in ('net view /domain:%dom%^|findstr /L /C:"\\"^|findstr /L /V /C:"\\%ComputerName%"') do (
 for /f "tokens=*" %%u in ('psloggedon -L %%c^|findstr /L /C:"/"') do (
  set work1=%%u
  call set work2=!!work1:%dom%=!!
  if "!work2!" NEQ "!work1!" for /f "Tokens=*" %%i in ('@echo %%c^|Findstr /L /I /V /G:%except%') do (
   psshutdown -o %%i

Open in new window

Microsoft DevelopmentScripting LanguagesProgramming

Avatar of undefined
Last Comment

8/22/2022 - Mon