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
Coachie

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
Kaktussoft

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
Coachie

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
Kaktussoft

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
Kaktussoft

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
Kaktussoft

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 WIN7 machine .. script works? Are you very sure?! Startup scripts run NOT elevated, so can't shutdown.
My System SpecsSystem Spec
30 Jan 2013   #7
DavidE

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

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
Kaktussoft

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 win7 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
Thread Forum
Windows 7 sometimes logon the user automatically - Spyware
I have a windows 7 that sometimes logon the user automatically. I checked the registry and also the settings that require the user to: Must Enter A User Name And Password To Use This Computer check box (is checked). the computer is win 7 pro 64 and the user is in the admin group. is this a...
General Discussion
Logon Wallpaper - automatically change w/ every logon
My method for automatically changing the Windows 7 logon/logoff wallpaper with every logon. Step 1: Use one of the many guides on the web to enable custom/oem logon wallpaper, such as Brink's: http://www.sevenforums.com/tutorials/5382-log-screen-change.html Step 2: Copy whatever JPEG...
Customization
Logon script not running on Win 7
Hi all, new here. Have a little experience with Win 7, a lot with Win XP. So here's my situation. I'm trying to create a login script for use on my work's PCs. Most all of our boxes are running XP. Putting this login script into the Starup folder works fine, the script runs on startup and...
General Discussion
Logon script issue...
Hi, I work in a fairly large company and we use a logon script (pushed thru GPO) utilizing "NET USE" to access shared drives. In XP, the system simply skips those drives which user has no access rights to and goes back straight to the C:\drive prompt. This effectively puts an end to the script...
Network & Sharing
PowerShell logon script
Ok, so this doesn't necessarily have to do with Windows 7, but I originally wanted to reply to a post on Vista forums and somehow I ended up here. Anyway... I actually tried all of this on Windows Server 2008 - set policies, scripts and logged on there. Here's one way that actually works. 1)...
Network & Sharing
Logon Script
I like to create small websites, just doing fun stuff with HTML and such. I thought it'd be easier to share the htdocs folder(I'm using XAMPP - that's where are all HTML etc files are) and edit those files / create new files from any comp in my network. So... I wanted to run a script (net use...
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 10:55.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App