Announcement

Collapse
No announcement yet.

force logoff user windows 7 from server

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • force logoff user windows 7 from server

    Hi, I don't want a gpo just a utility like shutdown /l but that could be executed from a remote station or server. THe station with the user logged is in a domain.
    I've seen many things, but nothing doing the job.
    Something like shootdown c: \\thecomputer /l

    I don't want to restart the computer, just logoff any user that is logged in.

    Many thanks

    Simon

  • #2
    Re: force logoff user windows 7 from server

    shutdown.exe has a -m switch that allows you to specify the machine name
    shutdown -l -m DC1 -t 0 for example

    Alternatively shutdown -i to go into interactive mode and get a GUI

    EDIT -- shutdown -i does not have a logoff option
    Also shutdown -h does not give the help
    Last edited by Ossian; 15th August 2013, 15:35.
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment


    • #3
      Re: force logoff user windows 7 from server

      Check usage on qwinsta.exe and rwinsta.exe. they are for forcing ts sessions closed but I think you might be able to do this with the console session as well. I'm not next to a computer at the moment or I would check myself...
      Rules of life:
      1. Never do anything that requires thinking after 2:30 PM
      2. Simplicity is godliness
      3. Scale with extreme prejudice


      I occasionally post using a savantphone, so please don't laugh too hard at the typos...

      Comment


      • #4
        Re: force logoff user windows 7 from server

        Originally posted by Ossian View Post
        shutdown.exe has a -m switch that allows you to specify the machine name
        shutdown -l -m DC1 -t 0 for example

        Alternatively shutdown -i to go into interactive mode and get a GUI

        EDIT -- shutdown -i does not have a logoff option
        Also shutdown -h does not give the help
        And I may add that that shutdown -l does not allow -m so I' cannot use it ...

        Comment


        • #5
          Re: force logoff user windows 7 from server

          Oops -- that's what I get for not reading the help properly

          How about PsShutdown?
          http://technet.microsoft.com/en-gb/s.../bb897541.aspx

          Someone also has a script:
          http://community.spiceworks.com/scri...remote-log-off
          Tom Jones
          MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
          PhD, MSc, FIAP, MIITT
          IT Trainer / Consultant
          Ossian Ltd
          Scotland

          ** Remember to give credit where credit is due and leave reputation points where appropriate **

          Comment


          • #6
            Re: force logoff user windows 7 from server

            Originally posted by Simoncu View Post
            And I may add that that shutdown -l does not allow -m so I' cannot use it ...

            You could use the script from here

            http://www.windowsnetworking.com/kba...otelogoff.html

            Code:
            strComputer = "" 
            Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
            Set colOperatingSystems = objWMIService.ExecQuery ("SELECT * FROM Win32_OperatingSystem") 
            For Each objOperatingSystem in colOperatingSystems 
            ObjOperatingSystem.Win32Shutdown(0) 
            Next
            As always please ensure that you test and understand this script thuoroughly before using in a live environment.

            Comment


            • #7
              Re: force logoff user windows 7 from server

              Originally posted by Ossian View Post
              Oops -- that's what I get for not reading the help properly

              How about PsShutdown?
              http://technet.microsoft.com/en-gb/s.../bb897541.aspx

              Someone also has a script:
              http://community.spiceworks.com/scri...remote-log-off

              I tried psshutdown, it has the option -o, but in my case (I have to try it again) it logged off the user AND shutted down the machine....

              THe script looks interesting, thanks, I think it's a good idea, as I'm not a programmer, it will help me; keep you posted.

              Comment


              • #8
                Re: force logoff user windows 7 from server

                What I have done which makes my life easier.
                I have a batch file which queries our citrix/terminal servers, or any where i need to check who's logged in, i will run the batch file as a domain admin (with something like runas) runas/user:domain\user "cmd"

                like
                @echo ----checking remote logins----
                quser /server:TerminalServer1
                quser /server:CitrixServer1
                Pause


                When I have found where the user is i will perform a remote logoff.
                c:\logoff 2 /server:TerminalServer1

                In a cmd window type logoff /? or quser /? for more info.

                ...Just my 2 cents.
                Please remember to award reputation points if you have received good advice.
                I do tend to think 'outside the box' so others may not always share the same views.

                MCITP -W7,
                MCSA+Messaging, CCENT, ICND2 slowly getting around to.

                Comment


                • #9
                  Re: force logoff user windows 7 from server

                  Originally posted by uk_network View Post
                  What I have done which makes my life easier.
                  I have a batch file which queries our citrix/terminal servers, or any where i need to check who's logged in, i will run the batch file as a domain admin (with something like runas) runas/user:domain\user "cmd"

                  like
                  @echo ----checking remote logins----
                  quser /server:TerminalServer1
                  quser /server:CitrixServer1
                  Pause


                  When I have found where the user is i will perform a remote logoff.
                  c:\logoff 2 /server:TerminalServer1

                  In a cmd window type logoff /? or quser /? for more info.

                  ...Just my 2 cents.
                  thanks, I have a question, do you do that also on workstations ? because logoff asks "SERVER/servername" so if I put a workstation name will it work ?

                  Basically,what I want to do is to erase user profiles on windows 7 pc on a classroom, where people log in with their domain\username. So after a while I get a LOT of profiles stored on the machine, and of course I could just force reboot the machine, but in case someone is still logged I wanted to log the user off before doing it. If it's too complicated, then too bad, I'll use psshutdown and reboot the machine. I never thought that it was so difficult to do sth like that in a domain. Thanks for your help anyway, I appreciated it very much.
                  And excuse my English, I'm a French speaking Swiss

                  Comment


                  • #10
                    Re: force logoff user windows 7 from server

                    I was correct. using qwinsta and rwinsta, you can query a computer to find what session is associated with a particular logon, then force that session to close:

                    Code:
                    c:\>qwinsta /server:uPN-laptop
                     SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
                     services                                    0  Disc
                     console           userPrincipalName         2  Active
                    
                    c:\>rwinsta 2 /server:uPN-laptop
                    
                    c:\>qwinsta /server:uPN-laptop
                     SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
                     services                                    0  Disc
                     console           			     2  Conn
                    This forces a logoff but allows the user to save data. Cool thing is you cant bypass the logoff by clicking "Cancel" to a save your work dialog...

                    And yes, this works on workstations, servers, terminal servers, headless servers, multi-user servers, kiosks etc as well.
                    Last edited by userPrincipalName; 16th August 2013, 22:47.
                    Rules of life:
                    1. Never do anything that requires thinking after 2:30 PM
                    2. Simplicity is godliness
                    3. Scale with extreme prejudice


                    I occasionally post using a savantphone, so please don't laugh too hard at the typos...

                    Comment


                    • #11
                      Re: force logoff user windows 7 from server

                      Hi, yes quser works on both server/workstations. For deleting profiles to reclaim disk space i would check out Delprof2, it removes the profiles and registry entrys too.

                      http://helgeklein.com/free-tools/del...deletion-tool/
                      Please remember to award reputation points if you have received good advice.
                      I do tend to think 'outside the box' so others may not always share the same views.

                      MCITP -W7,
                      MCSA+Messaging, CCENT, ICND2 slowly getting around to.

                      Comment


                      • #12
                        Re: force logoff user windows 7 from server

                        And yes, this works on workstations, servers, terminal servers, headless servers, multi-user servers, kiosks etc as well.
                        Many thanks. Appreciate your help.

                        Comment


                        • #13
                          Re: force logoff user windows 7 from server

                          If you're deleting profiles you'll probably have to reboot to release all the locks anyways. Also, with PsShutdown you should be able to log off the user without restarting. I've used it tons of times in my life for that very purpose.
                          Regards,
                          Jeremy

                          Network Consultant/Engineer
                          Baltimore - Washington area and beyond
                          www.gma-cpa.com

                          Comment

                          Working...
                          X