Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - RE: force logoff after time limit

Reply
 
Old 01-30-2009   #1 (permalink)
rkd


 
 

RE: force logoff after time limit

hello,

what about this:
# script begin
param(
[DateTime]$TimeSpan, #in minutes
[Switch]Force # used if logoff should be forced
)
$startTime = Get-Date
while( (Get-Date).Subtract( $startTime ).Minutes < $timeSpan ){
Sleep -sec 60
}
gwmi Win32_OperatingSystem -computer $computer -Filter "Primary=true" | %{
$_.Psbase.scope.options.EnablePrivileges = $TRUE # is necessary for
the Win32_Shutdown method
$_.Win32Shutdown( 4 * $( if( $force -eq $TRUE){1}else{0}) + 0 ) # for the
value of tz eparameter please refer to the msdn library
}
#script end

though i didn't evaluate the script i think it should work
Please consider that you can execute the script in a hidden window:
Powershell.exe /windowsstyle hidden ...

greetings reinhard

"cmoore01" wrote:
Quote:

> Too early in the morning, and not enough caffeine. Need a script that kicks
> off when a specific user logs in and will log them off after a set period of
> time, say 15-20 minutes. Would prefer something I can place in the startup
> folder for specific user(s) on a specific PC. Thanks In Advance...

My System SpecsSystem Spec
Old 01-31-2009   #2 (permalink)
Shay Levy [MVP]


 
 

Re: force logoff after time limit

Hi cmoore01,


Put a batch file in the user's startup folder

# log off user (/l) after 900 sec (/t in seconds) and force applications
to close (/f)
shutdown /l /t 900 /f


Keep in mind that the user can delete the file so consider adding it as a
registry entry under HKCU...Run.

---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar



c> Too early in the morning, and not enough caffeine. Need a script
c> that kicks off when a specific user logs in and will log them off
c> after a set period of time, say 15-20 minutes. Would prefer
c> something I can place in the startup folder for specific user(s) on a
c> specific PC. Thanks In Advance...
c>


My System SpecsSystem Spec
Old 02-04-2009   #3 (permalink)
Josh Einstein


 
 

Re: force logoff after time limit

Can't group policy do this?

"cmoore01" <cmoore01@xxxxxx> wrote in message
news:2BF1773F-6C4C-45C5-8058-A19A7556502C@xxxxxx
Quote:

> Too early in the morning, and not enough caffeine. Need a script that
> kicks
> off when a specific user logs in and will log them off after a set period
> of
> time, say 15-20 minutes. Would prefer something I can place in the
> startup
> folder for specific user(s) on a specific PC. Thanks In Advance...
My System SpecsSystem Spec
Old 02-04-2009   #4 (permalink)
Shay Levy [MVP]


 
 

Re: force logoff after time limit

Hello cmoore01,

As Josh suggested, best way is to push it via GPO, put this in the login
script:



On Error Resume Next

Set oNet = CreateObject("WScript.Network")
Set oShell = CreateObject("WScript.Shell")

If oNet.UserName = "user" Then
' run in hidden window
' dont wait for the program to finish executing before
' continuing to the next statement in your script
oShell.Run "shutdown /l /t 900 /f",0,False
End If



---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar


c> Looks good. Forgot about the shutdown command. Is there a way to do
c> this in PS? I tried the script above and still struggling to make it
c> work. I am missing something. I had someone else look also and we
c> are scratching our heads.
c>
c> Much appreciated though for remiding me about Shutdown. Good interim
c> solution until I can hide what is happening with PS.
c>
c> "Shay Levy [MVP]" wrote:
c>
Quote:
Quote:

>> Hi cmoore01,
>>
>> Put a batch file in the user's startup folder
>>
>> # log off user (/l) after 900 sec (/t in seconds) and force
>> applications
>> to close (/f)
>> shutdown /l /t 900 /f
>> Keep in mind that the user can delete the file so consider adding it
>> as a registry entry under HKCU...Run.
>>
>> ---
>> Shay Levy
>> Windows PowerShell MVP
>> http://blogs.microsoft.co.il/blogs/ScriptFanatic
>> PowerShell Toolbar: http://tinyurl.com/PSToolbar
>> c> Too early in the morning, and not enough caffeine. Need a script
>> c> that kicks off when a specific user logs in and will log them off
>> c> after a set period of time, say 15-20 minutes. Would prefer
>> c> something I can place in the startup folder for specific user(s)
>> on a
>> c> specific PC. Thanks In Advance...
>> c>

My System SpecsSystem Spec
Old 02-04-2009   #5 (permalink)
Josh Einstein


 
 

Re: force logoff after time limit

Actually I was just wondering out loud if group policy had a setting to log
a user off after x number of minutes of inactivity. I'm not an admin type
but it seems like a pretty reasonable thing to do at a bank or something.

Josh

"Shay Levy [MVP]" <no@xxxxxx> wrote in message
news:37162f67681088cb54f9a7c3d650@xxxxxx
Quote:

> Hello cmoore01,
>
> As Josh suggested, best way is to push it via GPO, put this in the login
> script:
>
>
>
> On Error Resume Next
>
> Set oNet = CreateObject("WScript.Network")
> Set oShell = CreateObject("WScript.Shell")
>
> If oNet.UserName = "user" Then
> ' run in hidden window
> ' dont wait for the program to finish executing before ' continuing to the
> next statement in your script
> oShell.Run "shutdown /l /t 900 /f",0,False
> End If
>
>
>
> ---
> Shay Levy
> Windows PowerShell MVP
> http://blogs.microsoft.co.il/blogs/ScriptFanatic
> PowerShell Toolbar: http://tinyurl.com/PSToolbar
>
>
> c> Looks good. Forgot about the shutdown command. Is there a way to do
> c> this in PS? I tried the script above and still struggling to make it
> c> work. I am missing something. I had someone else look also and we
> c> are scratching our heads.
> c> c> Much appreciated though for remiding me about Shutdown. Good
> interim
> c> solution until I can hide what is happening with PS.
> c> c> "Shay Levy [MVP]" wrote:
> c>
Quote:
Quote:

>>> Hi cmoore01,
>>>
>>> Put a batch file in the user's startup folder
>>>
>>> # log off user (/l) after 900 sec (/t in seconds) and force
>>> applications
>>> to close (/f)
>>> shutdown /l /t 900 /f
>>> Keep in mind that the user can delete the file so consider adding it
>>> as a registry entry under HKCU...Run.
>>>
>>> ---
>>> Shay Levy
>>> Windows PowerShell MVP
>>> http://blogs.microsoft.co.il/blogs/ScriptFanatic
>>> PowerShell Toolbar: http://tinyurl.com/PSToolbar
>>> c> Too early in the morning, and not enough caffeine. Need a script
>>> c> that kicks off when a specific user logs in and will log them off
>>> c> after a set period of time, say 15-20 minutes. Would prefer
>>> c> something I can place in the startup folder for specific user(s)
>>> on a
>>> c> specific PC. Thanks In Advance...
>>> c>
>
>
My System SpecsSystem Spec
Old 02-04-2009   #6 (permalink)
Karl Mitschke


 
 

Re: force logoff after time limit

Hello cmoore01,
Quote:

> The PCs are not part of a domain, so I will not be able to use GPO.
> Wish they were part of my domain, but they are stand alone PCs. This
> is why I was hoping there was a way to use PS. I did try to use your
> suggestion of Shutdown, but regardless if I tried it on a domain
> attached XP Pro (SP3), or a standalone, I either received the help
> screen, or it logged me of immeadiately, do delays. I tried the GUI
> (-i switch) with the same result. Tried it with both CMD and Command.
> I tried to use the first suggestion with the WMI settings, but could
> not get tat to work either.
>
> thanks so far.
When I had to do this for kiosks, a few years ago, I wrote a custom screen
saver, and a windows service in C#.

I'm not sure if powershell can access a screensaver, but if it could you'd
have to have the powershell script running constantly, looking for a screensaver.

If you're at all comfortable with C#, I could send you the code.

Karl


My System SpecsSystem Spec
Old 02-27-2009   #7 (permalink)
Al Dunbar


 
 

Re: force logoff after time limit


"cmoore01" <cmoore01@xxxxxx> wrote in message
news:F3AE0C07-4FE6-455D-89E8-74E8015BAC4C@xxxxxx
Quote:

> Here is what I finally was able to cobble together:
>
> The followinig is a VB script:
>
> CONST waitFor = 15 ' minutes
> wscript.Sleep waitFor * 60000 'constant x 1,000 milliseconds/second x 60
> seconds/minute
> CreateObject("Wscript.Shell").Run "c:\windows\system32\logoff.exe", 0,
> True
>
> The script is then embedded in a shortcut added to the startup folder as
> follows:
>
> c:\windows\system32\wscript.exe \\server\share\logoff_after_2_hours.vbs
> //t:9000 //b
>
> Should mentione that the //t switch is the timeout for the script
> and just needs to be longer than the script sleeps.
> The //b is probably not needed, but tells the script to hide any output
> from
> the user.
> Using wscript makes it run without a window to keep the user from closing
> it.
>
>
> works like a charm
Of course, if the user had any knowledge of these things, he might deduce
that some invisible process was watching the clock. He then might try
terminating any processes that did not seem to be contributing to his
purpose, including the wscript.exe process running the script.

Sure, not too likely, and not very convenient - unless he writes a script to
terminate the process and shares this with his friends.


/Al
Quote:

> thanks all who helped in the discussion.
> "cmoore01" wrote:
>
Quote:

>> Too early in the morning, and not enough caffeine. Need a script that
>> kicks
>> off when a specific user logs in and will log them off after a set period
>> of
>> time, say 15-20 minutes. Would prefer something I can place in the
>> startup
>> folder for specific user(s) on a specific PC. Thanks In Advance...

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Set pc to hibernate/shutdown/logoff etc after certain time General Discussion
how to force logoff when workstation is locked? Vista General
need to have a web based time sheet appear at logon and logoff Vista security
Can't force users to logoff Vista account administration
Force user logoff from Task Manager Vista performance & maintenance


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

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 34 35 36 37 38 39 40 41 42 43 44 45 46