Auto lock the system after Autologon and send notification.

The steps outlined below would help you with three things:

  1. Autologon to a system with a particular account
  2. Send a notification mail when that account is logged in to the system after a reboot
  3. Lock the system automatically once the account has been logged on

Step 1 – Enable Autologon:

  1. Go to Start > Run and put "regedit.exe" and click "Ok"
  2. Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon in Registry Editor
  3. Change the REG_SZ "DefaultUserName" value to the username you want to autologon to the system
  4. Change the REG_SZ "DefaultPassword" value to the password of the user you want to autologon to the system. (If the key does not exist then do create it)
  5. Change the REG_SZ "DefaultdomainName" value to the domain name you wish to logon to (If the key does not exist then do create it)
  6. Add a new REG_SZ "AutoAdminLogon" and set the value to 1
  7. Close Registry editor

Step 2 – Prepare notification files:

  1. Create a directory C:\Autologon;
  2. Create the files chkLogtime.vbs, Locksystem.cmd and Delchklog.cmd with the contents mentioned in Annexure I below

Step 3 – Setup up notification and autolock:

  1. Go to Start > Run and put "regedit.exe" and click "Ok"
  2. Navigate to HKEY_USERS\<SID of particular user>\software\Microsoft\Windows\CurrentVersion\Run in Registry Editor
  3. Add a new REG_SZ "ChkLogtime" and set the value to C:\Autologon\ChkLogtime.vbs
  4. Add a new REG_SZ "LockSystem" and set the value to C:\Autologon\Locksystem.cmd

Step 4 – Enable notification:

  1. Open Group Policy Object Editor
  2. Navigate to Local Computer Policy\Computer Configuration\Windows Settings\Scripts\ (Startup/shutdown)
  3. Double click on Shutdown in the right hand pane
  4. Click Add and Browse to the file C:\Autologon\Delchklog.cmd
  5. Click OK twice and close Group Policy Object Editor

NOTES:

  1. The Autologon would not work if the LegalNotice warning window is enabled at the domain level. You might have to do additional configuration to disable this.
  2. Automatic reboots will not work unless you specify ‘/F’ switch in your reboot script.

Annexure I


ChkLogTime.vbs

Dim WShell,SrvName
Set objFSO = Wscript.CreateObject("Scripting.FileSystemObject")
Set WShell = WScript.CreateObject("WScript.Shell")
If objFSO.FileExists("C:\Autologon\ChkLogTimeskip.txt") Then
wscript.Quit
Else
Set objFile = objFSO.CreateTextFile("C:\Autologon\ChkLogTimeskip.txt")
SrvName = Trim(WShell.ExpandEnvironmentStrings("%COMPUTERNAME%"))
User=Trim(WShell.ExpandEnvironmentStrings("%USERNAME%"))
LogTime= User &" is successfully logged onto " & SrvName &" after scheduled reboot at "& Now
objFile.writeline LogTime
objfile.close
Call SendMailAlerts(LogTime, User, SrvName)
End IF
Wscript.Quit
#################### Send Email Alerts ########################
Function SendMailAlerts(LogTime, User, SrvName)
RecipientList ="mukulag@gmail.com"
smtpsrv = "smtp.mukulag.com"
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "MyServer@mukulag.com"
objEmail.To = RecipientList
objEmail.Subject = User & " has logged on succesfully to " & SrvName " at "  & Now
objEmail.TextBody = LogTime
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing&quot;) = 2
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver&quot;) = smtpsrv
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport&quot;) = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End Function
‘##################### End Send Email Alerts ###########################

Locksystem.cmd

rundll32.exe user32.dll, LockWorkStation

DelChkLog.cmd

Del C:\Autologon\ChkLogTimeskip.txt /F

————– End of Document —————–

Tags: Windows Server 2003

Published Date: 20071207

Advertisements