Can I force a user to log off automatically through a logon script?


  1. Posts : 2
    Windows Professional 32 & 64
       #1

    Can I force a user to log off automatically through a logon script?


    Hi there

    I've trying to invoke a fix on the fly and have got a mixed windows workstation environment on my network. For particular reasons, I don't want my windows XP users to use a Windows 7 machine and equally I don't want a Windows 7 user to use a Windows XP machine. Silly I know but there you go.

    I've set up a couple of WMI filters that determine the machine type and have used the following script to ensure that each user type is logged off and the PC restarted.

    Option Explicit
    Dim objShell
    MsgBox"The detected logon method is not supported " & chr(13) & chr(13) & "Please revert to using your own computer." & chr(13) & chr(13) & "This computer will now restart" & chr(13) & chr(13),0,"Invalid Logon Detected."
    Set objShell = WScript.CreateObject("WScript.Shell")
    objShell.Run "C:\WINDOWS\system32\shutdown.exe -r -f -t 0"


    For the Windows XP users on Windows 7 machines it works fine, however when a Windows 7 user logs into a Windows XP machine, it displays the message but won't do the restart bit on the Windows 7 machines.

    Do I need to create some elevated permissions for my windows 7 machines.
      My Computer


  2. Posts : 10,796
    Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
       #2

    Try to run interactively.

    C:\WINDOWS\system32\shutdown.exe -r -f -t 0

    works on winxp?
    ------------
    Why did you create those user accounts? You don't let them logon! You don't simply log them off but even shutdown.
      My Computer


  3. Posts : 2
    Windows Professional 32 & 64
    Thread Starter
       #3

    Sorry but I don't understand what you mean by running that command interactively.

    I need this shutdown/restart facility to run as they log in (i.e. Automatically).

    I can't run the command for them.

    It needs to be automated as the users log in.
    :)
      My Computer


  4. Posts : 10,796
    Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
       #4

    Coachie said:
    Sorry but I don't understand what you mean by running that command interactively.

    I need this shutdown/restart facility to run as they log in (i.e. Automatically).

    I can't run the command for them.

    It needs to be automated as the users log in.
    :)
    In winxp open command prompt and type
    C:\WINDOWS\system32\shutdown.exe -r -f -t 0

    That reboots computer fine?
      My Computer


  5. Posts : 10,796
    Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
       #5

    Why did you create those user accounts? You don't let them logon! What should they be able to do with that account?
      My Computer


  6. Posts : 10,796
    Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
       #6

    Coachie said:
    Hi there

    I've trying to invoke a fix on the fly and have got a mixed windows workstation environment on my network. For particular reasons, I don't want my windows XP users to use a Windows 7 machine and equally I don't want a Windows 7 user to use a Windows XP machine. Silly I know but there you go.

    I've set up a couple of WMI filters that determine the machine type and have used the following script to ensure that each user type is logged off and the PC restarted.

    Option Explicit
    Dim objShell
    MsgBox"The detected logon method is not supported " & chr(13) & chr(13) & "Please revert to using your own computer." & chr(13) & chr(13) & "This computer will now restart" & chr(13) & chr(13),0,"Invalid Logon Detected."
    Set objShell = WScript.CreateObject("WScript.Shell")
    objShell.Run "C:\WINDOWS\system32\shutdown.exe -r -f -t 0"

    For the Windows XP users on Windows 7 machines it works fine, however when a Windows 7 user logs into a Windows XP machine, it displays the message but won't do the restart bit on the Windows 7 machines.

    Do I need to create some elevated permissions for my windows 7 machines.
    If a winxp user (only allowed to logon on winxp machine) logs on on WIN7 machine .. script works? Are you very sure?! Startup scripts run NOT elevated, so can't shutdown.
      My Computer


  7. Posts : 6,330
    Multi-Boot W7_Pro_x64 W8.1_Pro_x64 W10_Pro_x64 +Linux_VMs +Chromium_VM
       #7

    It looks like the syntax might have changed since XP, and the "-" for XP is a "/" for Win7 switches.
    Take a look here, and try using the "/" for Win 7.
    MS-DOS shutdown command help

    For XP you might need objShell.Run "C:\WINDOWS\system32\shutdown.exe -r -f -t 0"
    For W7 you might need objShell.Run "C:\WINDOWS\system32\shutdown.exe /r /f /t 0"
      My Computer


  8. Posts : 6,330
    Multi-Boot W7_Pro_x64 W8.1_Pro_x64 W10_Pro_x64 +Linux_VMs +Chromium_VM
       #8

    I tested both of these commands from a Command Prompt (CMD) window in Win 7, and they both restarted my PC.
    So now I don't think it's the "-" vs "/" issue.
    fyi, I log in as a Standard User, and did NOT use an elevated CMD.

    Can you add a debug or trace statement to your script to see what, if anything, it returns for troubleshooting?
      My Computer


  9. Posts : 10,796
    Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
       #9

    You better use ntrights.exe to prevent users to logon interactively.
    Code:
    ntrights   -U   "User or Group"   +R   SeDenyInteractiveLogonRight
    For example:
    Code:
    ntrights  -U  "JohnDoe"  +R  SeDenyInteractiveLogonRight
    To revert this:
    Code:
    ntrights  -U  "JohnDoe"  -R  SeDenyInteractiveLogonRight
    Place ntrights.exe in c:\windows\system32.
    Run from command prompt in winxp. In win7 run from Elevated Command Prompt

    Works?
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 05:38.
Find Us