Solved

Login script to run only upon first login of the day

Posted on 2013-01-23
9
590 Views
Last Modified: 2013-01-29
I need to write a VBscript that will display a message only upon a user's first login of the day. These users move around quite a bit during the day and are always logging into different computers. My initial plan was to have the script look at the user account's last login attribute and only display the message if the last login date is not the same as the current date. However, I started thinking that this might not work because the last login attribute is not replicated to all domain controllers. Also, since this is to be a login script the last login is technically going to be the most recent login so the last login date and the current date would always be the same. Is there a better way to handle this? Oh, I forgot to mention this would be deployed as a login script via GPO.
0
Comment
Question by:mcpp661
  • 4
  • 3
  • 2
9 Comments
 
LVL 14

Assisted Solution

by:athomsfere
athomsfere earned 250 total points
ID: 38810023
If you use home drives, you could place a file on the users home drives with the login date, on login it checks the Home drive, and the date. If its the current day, it exits, otherwise it proceeds as well as changes the file to contain the current date.
0
 

Author Comment

by:mcpp661
ID: 38810141
I do use home drives for most users, however the users that are to see this message from the login script have no need for a home drive.
0
 
LVL 14

Expert Comment

by:athomsfere
ID: 38810201
A share elsewhere available?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:mcpp661
ID: 38810811
I may have to make one up.
0
 
LVL 14

Expert Comment

by:athomsfere
ID: 38811245
That seems the simplest route to me.
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 250 total points
ID: 38817393
Hi, this script is a simple demonstration of displaying a message once per day for any user, by storing a file in their temporary folder to check the date against.

Regards,

Rob.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
strStamp = objShell.ExpandEnvironmentStrings("%TEMP%") & "\LogonScriptStamp.txt"
blnShowMessage = False
If objFSO.FileExists(strStamp) = False Then
	blnShowMessage = True
Else
	If objFSO.GetFile(strStamp).DateLastModified < Date Then blnShowMessage = True
End If
If blnShowMessage = True Then
	Set objFile = objFSO.CreateTextFile(strStamp, True)
	objFile.Close
	Set objADSysInfo = CreateObject("ADSystemInfo")
	Set objUser = GetObject("LDAP://" & objADSysInfo.Username)
	MsgBox "Hello " & objUser.DisplayName & "," & vbCrLf & "You have logged in for the first time today on " & objNetwork.ComputerName
End If

Open in new window

0
 

Author Comment

by:mcpp661
ID: 38820580
Ah.....I'm going to test it at work on Monday. Thanks Rob!
0
 

Author Closing Comment

by:mcpp661
ID: 38831291
Thanks guys. I decided to award both of you points since the first poster had the idea of using a file on the home drives (which is what I'm going to have to do since these users log into multiple stations each day) and Rob provided code.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 38832889
No problem.  You can change
strStamp = objShell.ExpandEnvironmentStrings("%TEMP%") & "\LogonScriptStamp.txt"

to
strStamp = "N:\LogonScriptStamp.txt"

or something to put the file in a different location.  That approach is obviously used where you want the message to appear once per day regardless of how many computers they log on to, whereas the local %TEMP% could be used to have it once per computer instead.

Regards,

Rob.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP CDO - Limiting Connections 2 50
DHCP scope restore question Server 2003 to 2012R2 6 59
Update Access FrontEnd by Version # 9 42
VBScript Write Column Headers 3 37
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
A quick step-by-step overview of installing and configuring Carbonite Server Backup.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question