Login | |
|
 |
Account Expiring Soon Script - 1/25/2008 3:55:04 AM
|
|
 |
|
| |
xybg5
Posts: 8
Score: 0
Joined: 1/24/2008
Status: offline
|
Hey all, having some issues with a VB script and looks like I could find some anwsers here. Did a search about this and didn't find anything similar. Basically what I want to do is insert this script into our current logon script and let the current user know at logon if thier account will expire soon. I have this section of code I have been playing with but it hits an error when I run it, being new to VB I don't know if its syntax, code, or something else. Option Explicit Dim strUserName, strCrDate, objAcctExp, CrUser Dim strCrDomain, strAcctExp, strSysInfo Dim UserINfo, strDateDiff Set strSysInfo = CreateObject("ADSystemInfo") Set CrUser = GetObject("LDAP://" & strSysInfo.UserName & "") strCrDate = Date() strAcctExp = CrUser.AccountExpirationDate strDateDiff = datediff("d", strCrDate, strAcctExp) If strDateDiff <= 5 Then msgbox "Your account will expire in " & strDateDiff & " days. Please contact your system administrator for help." Elseif strDateDiff > 5 Then wscript.quit End If wscript.quit Specifically I get Line: 6 char: 1 error: 0x80005000 code: 80005000 scource: (null) I don't take credit for the code, I'm just getting to the point of following what its trying to do myself. Any help would be appreciated.
|
|
| |
|
|
|
 |
RE: Account Expiring Soon Script - 1/25/2008 4:06:53 AM
|
|
 |
|
| |
Rischip
Posts: 502
Score: 2
Joined: 3/26/2007
Status: offline
|
Try changing Set CrUser = GetObject("LDAP://" & strSysInfo.UserName & "") to Set CrUser = GetObject("LDAP://" & strSysInfo.UserName)
_____________________________
Rischip Author of - The Grim Linker
|
|
| |
|
|
|
 |
RE: Account Expiring Soon Script - 1/25/2008 4:46:56 AM
|
|
 |
|
| |
dm_4ever
Posts: 2641
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
|
If you run this it will obviously want to display when your account expires....have you set an expiration date on your account? This is account expiration and not password expiration...I hope you haven't confused both.
_____________________________
dm_4ever My philosophy: K.I.S.S - Keep It Simple Stupid Read Me: http://www.visualbasicscript.com/m_24727/tm.htm Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Account Expiring Soon Script - 1/28/2008 1:27:40 AM
|
|
 |
|
| |
ebgreen
Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
|
Are you sure that a regular user has the rights to run DSQuery. I would not expect them to. As for how to get the date, look at the documentation for the WshShell object and it's .Execute method. It will execute the command and expose the STDOUT to your script to see what the date is.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Account Expiring Soon Script - 1/28/2008 4:10:20 AM
|
|
 |
|
| |
xybg5
Posts: 8
Score: 0
Joined: 1/24/2008
Status: offline
|
Yes, normal user accounts can run DSQuery/DSGet, I'm doing all testing for my normal account to make sure. After looking through the domain logon scripts everything is in kixtart so I made a kix script to do the same thing, don't know what the security issue is with our domain but its above my pay scale to worry about it. After testing under an admin account the code in the OP does work fine though, if it can help anyone in the future. EDIT: Was kinda eating at me that this wouldn't work so I did this as a work around: Put an entry in the logon.bat file calling DSQuery/DSGet and piping to a text file then read that date from the file instead of pulling it from LDAP. Logon.bat: dsquery user -samid %username% | dsget user -acctexpires > "C:\Documents and Settings\expire.txt" wscript \\YOURDC\Netlogon\AccountExpire.vbs del "C:\Documents and Settings\expire.txt" VBS File: Const ForReading = 1 Dim a, strAcctExp, strDateDiff Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile _ ("C:\Documents and Settings\expire.txt", ForReading) a = objTextFile.ReadLine strAcctExp = objTextFile.ReadLine objTextFile.Close strCrDate = Date() strDateDiff = datediff("d", strCrDate, strAcctExp) If strDateDiff <= 14 Then msgbox "Your account will expire in " & strDateDiff & " days. Please contact an administrator for help." Elseif strDateDiff > 14 Then wscript.quit End If wscript.quit Probably a better looking way to code this, but with my limited VBS skills thats what I came up with, works pretty well for my situation to.
< Message edited by xybg5 -- 1/29/2008 6:09:50 AM >
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|