Re: script at logon

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Torgeir Bakken \(MVP\) (Torgeir.Bakken-spam_at_hydro.com)
Date: 02/04/05


Date: Fri, 04 Feb 2005 16:43:47 +0100

anonymous@discussions.microsoft.com wrote:

> Dear Torgeir,
>
> Thank you for your answer. I will live this option in the
> background for a while for the reasons Scott explained: I
> have never hidden the shell or the Explorer in such a way
> and I'm not sure how I could recover it (i.e. how could I
> edit the register again to change the values).
Hi

The way to recover is to press Ctrl+Alt+Delete and then select
"Task Manager", then "New Task...". You can now start regedit.exe,
or explorer.exe or any other program you want to. If you don't
want ordinary users to be able to do the same, you will need
to configure a policy that disable it for them, e.g. the
"Remove Task Manager" policy under "User Configuration\Administrative
Templates\System\Ctrl+Alt+Del Options"

Also, if you are not able to add a logoff routine to your library
software, you will need to add something that does log the user off
when the user exits the library software.

You could e.g. add the script below in a scheduled task that is
configured to start at user logon.

The script goes into a loop and checks for an executable every
second (notepad.exe in this example). When it detects that the app
is not running, the script will log off the user.

'--------------------8<----------------------

Const EWX_LOGOFF = 0
Const EWX_FORCE = 4

sProcessName = "notepad.exe"

sComputer = "." ' use "." for local computer

' necessary to use the RemoteShutdown privilege to log off another
' user than the one defined in the scheduled task.
Set oWmi = GetObject("winmgmts:" _
     & "{impersonationLevel=impersonate,(RemoteShutdown)}!\\" _
     & sComputer & "\root\cimv2")

WScript.Sleep 5000 ' wait 5 seconds before starting checking

Do
   Set colProcessList = oWmi.ExecQuery _
       ("Select * from Win32_Process Where Name = '" & sProcessName & "'")

   If colProcessList.Count = 0 Then
     Exit Do
   End If
   WScript.Sleep 1000 ' wait 1 second before checking again
Loop

Set colOpSys = oWmi.ExecQuery("select * from Win32_OperatingSystem")

For Each oOpSys in colOpSys
   Set oOS = oOpSys : Exit For
Next
oOS.Win32shutdown EWX_LOGOFF + EWX_FORCE

'--------------------8<----------------------

-- 
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx


Relevant Pages

  • Re: control CPU usage
    ... My first question is whether the pyHook event is calling the SendKeys ... The task manager has far too simplistic ... I included my main script for your reference. ... paragraph = rc.ProcessEvent ...
    (comp.lang.python)
  • Re: control CPU usage
    ... The script monitors global input using PyHook, ... you're using SendKeys to generate a keystroke to the other process. ... My first question is whether the pyHook event is calling the SendKeys function directly (after your "lengthy" calculation) or whether there are other events firing off in between. ... The task manager has far too simplistic visibility to be useful for this purpose. ...
    (comp.lang.python)
  • Re: Terminating a process
    ... the exe file still shows up in the task manager. ... from the Script Center's sample library ... ... >> Dennis Hancy ...
    (microsoft.public.scripting.vbscript)
  • Re: .vbs file only locks up inside a batch file.. why?
    ... instance in the Task Manager indicating that the script engine instance was ... The CD drawer does close with the double .Eject method in the script. ... But to get the vbs file to ... >>>release control back the batch file that it was called from, ...
    (microsoft.public.scripting.vbscript)
  • Re: Remove duplicate files [POSIX script]
    ... I added in a hurry before I posted the script. ... In addition to the algorithmic complexity one should also note that ...
    (comp.unix.shell)