Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.



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

30 Jan 2013   #1

Windows Professional 32 & 64
 
 
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 System SpecsSystem Spec
30 Jan 2013   #2

Microsoft Community Contributor Award Recipient

Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
 
 

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 System SpecsSystem Spec
30 Jan 2013   #3

Windows Professional 32 & 64
 
 

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 System SpecsSystem Spec
.


30 Jan 2013   #4

Microsoft Community Contributor Award Recipient

Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
 
 

Quote   Quote: Originally Posted by Coachie View Post
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 System SpecsSystem Spec
30 Jan 2013   #5

Microsoft Community Contributor Award Recipient

Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
 
 

Why did you create those user accounts? You don't let them logon! What should they be able to do with that account?
My System SpecsSystem Spec
30 Jan 2013   #6

Microsoft Community Contributor Award Recipient

Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
 
 

Quote   Quote: Originally Posted by Coachie View Post
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 Windows 7 machine .. script works? Are you very sure?! Startup scripts run NOT elevated, so can't shutdown.
My System SpecsSystem Spec
30 Jan 2013   #7

Win 7 Pro x64 SP1, Win 7 Ult x86 SP1
 
 

It looks like the syntax might have changed since XP, and the "-" for XP is a "/" for Windows 7 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 Windows 7 you might need objShell.Run "C:\WINDOWS\system32\shutdown.exe /r /f /t 0"
My System SpecsSystem Spec
30 Jan 2013   #8

Win 7 Pro x64 SP1, Win 7 Ult x86 SP1
 
 

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 System SpecsSystem Spec
30 Jan 2013   #9

Microsoft Community Contributor Award Recipient

Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
 
 

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 Windows 7 run from Elevated Command Prompt

Works?
My System SpecsSystem Spec
Reply

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





Thread Tools



Similar help and support threads for2: Can I force a user to log off automatically through a logon script?
Thread Forum
Logon Wallpaper - automatically change w/ every logon Customization
Logon script not running on Win 7 General Discussion
Script Logon into websites Software
Logon script issue... Network & Sharing
PowerShell logon script Network & Sharing
Logon Script Network & Sharing
Use GP or logon/logoff script Network & Sharing

Our Sites

Site Links

About Us

Find 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 03:01 PM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33