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

Coachie

New member
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

Computer Manufacturer/Model Number
HP 6200 SFF
OS
Windows Professional 32 & 64
CPU
Core i3
Motherboard
HP
Memory
4GB
Graphics Card(s)
on board
Sound Card
on board
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

Computer type
Laptop
Computer Manufacturer/Model Number
ACER ASPIRE 5742G
OS
Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz
Motherboard
Acer Aspire 5742G
Memory
4,00 GB
Graphics Card(s)
ATI Mobility Radeon HD 5400 Series
Sound Card
(1) AMD High Definition Audio Device (2) Realtek High Defi
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 60 Hz
Hard Drives
WDC WD5000BEVT-22ZAT0
Sorry but I don't understand what you mean by running that command interactively.:o

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

Computer Manufacturer/Model Number
HP 6200 SFF
OS
Windows Professional 32 & 64
CPU
Core i3
Motherboard
HP
Memory
4GB
Graphics Card(s)
on board
Sound Card
on board
Sorry but I don't understand what you mean by running that command interactively.:o

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

Computer type
Laptop
Computer Manufacturer/Model Number
ACER ASPIRE 5742G
OS
Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz
Motherboard
Acer Aspire 5742G
Memory
4,00 GB
Graphics Card(s)
ATI Mobility Radeon HD 5400 Series
Sound Card
(1) AMD High Definition Audio Device (2) Realtek High Defi
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 60 Hz
Hard Drives
WDC WD5000BEVT-22ZAT0
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

Computer type
Laptop
Computer Manufacturer/Model Number
ACER ASPIRE 5742G
OS
Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz
Motherboard
Acer Aspire 5742G
Memory
4,00 GB
Graphics Card(s)
ATI Mobility Radeon HD 5400 Series
Sound Card
(1) AMD High Definition Audio Device (2) Realtek High Defi
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 60 Hz
Hard Drives
WDC WD5000BEVT-22ZAT0
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

Computer type
Laptop
Computer Manufacturer/Model Number
ACER ASPIRE 5742G
OS
Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz
Motherboard
Acer Aspire 5742G
Memory
4,00 GB
Graphics Card(s)
ATI Mobility Radeon HD 5400 Series
Sound Card
(1) AMD High Definition Audio Device (2) Realtek High Defi
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 60 Hz
Hard Drives
WDC WD5000BEVT-22ZAT0
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

Computer type
PC/Desktop
Computer Manufacturer/Model Number
home built
OS
Multi-Boot W7_Pro_x64 W8.1_Pro_x64 W10_Pro_x64 +Linux_VMs +Chromium_VM
CPU
AMD Athlon II x4 620
Motherboard
Gigabyte GA-MA785G-UD3H
Memory
6GB GSkill DDR2 800
Graphics Card(s)
AMD 4670 GPU + AMD 4200 IGP
Sound Card
on board Realtek ALC889A
Monitor(s) Displays
RCA 40" LCD TV, Insignia 32" LCD TV, HP 15" LCD monitor
Screen Resolution
1680 x 1050
Hard Drives
OCZ Vertex 3 120GB,
Samsung F3 1TB (3),
Several others - WD, Seagate, Hitachi, ...
PSU
Corsair 500 W
Case
Rosewill mid tower
Cooling
CM 90mm rifle
Keyboard
Gyration wireless, Logitech wireless, Dell USB wired
Mouse
Gyration wireless, Logitech wireless, V7 USB wired
Internet Speed
Spectrum - 100Mbps D / 10Mbps U
Antivirus
Avast, MBAM3, EMET, WinPatrol
Browser
Pale Moon, Firefox, IE
Other Info
2 multi-boot PC's
Mainly HTPC/Office/Gen purpose (no gaming).
Trendnet USB KVM.
LG DVD burner/Blue Ray Player.
Tray system for removable SATA backup drives.

Not currently OCd, under-volted.
I use Hybrid sleep, rarely re-boot or shutdown.

Hauppauge HD-PVR, Avermedia PCIe TV Tuner, Hauppauge PCI TV Tuner.
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

Computer type
PC/Desktop
Computer Manufacturer/Model Number
home built
OS
Multi-Boot W7_Pro_x64 W8.1_Pro_x64 W10_Pro_x64 +Linux_VMs +Chromium_VM
CPU
AMD Athlon II x4 620
Motherboard
Gigabyte GA-MA785G-UD3H
Memory
6GB GSkill DDR2 800
Graphics Card(s)
AMD 4670 GPU + AMD 4200 IGP
Sound Card
on board Realtek ALC889A
Monitor(s) Displays
RCA 40" LCD TV, Insignia 32" LCD TV, HP 15" LCD monitor
Screen Resolution
1680 x 1050
Hard Drives
OCZ Vertex 3 120GB,
Samsung F3 1TB (3),
Several others - WD, Seagate, Hitachi, ...
PSU
Corsair 500 W
Case
Rosewill mid tower
Cooling
CM 90mm rifle
Keyboard
Gyration wireless, Logitech wireless, Dell USB wired
Mouse
Gyration wireless, Logitech wireless, V7 USB wired
Internet Speed
Spectrum - 100Mbps D / 10Mbps U
Antivirus
Avast, MBAM3, EMET, WinPatrol
Browser
Pale Moon, Firefox, IE
Other Info
2 multi-boot PC's
Mainly HTPC/Office/Gen purpose (no gaming).
Trendnet USB KVM.
LG DVD burner/Blue Ray Player.
Tray system for removable SATA backup drives.

Not currently OCd, under-volted.
I use Hybrid sleep, rarely re-boot or shutdown.

Hauppauge HD-PVR, Avermedia PCIe TV Tuner, Hauppauge PCI TV Tuner.
You better use ntrights.exe to prevent users to logon interactively.
Code:
[B]ntrights   -U   "[COLOR=red]User or Group[/COLOR]"   +R   SeDenyInteractiveLogonRight[/B]

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 http://www.sevenforums.com/tutorials/783-elevated-command-prompt.html

Works?
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
ACER ASPIRE 5742G
OS
Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz
Motherboard
Acer Aspire 5742G
Memory
4,00 GB
Graphics Card(s)
ATI Mobility Radeon HD 5400 Series
Sound Card
(1) AMD High Definition Audio Device (2) Realtek High Defi
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 60 Hz
Hard Drives
WDC WD5000BEVT-22ZAT0
Back
Top