Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Account Expiring Soon Script

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,55973
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Account Expiring Soon Script
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 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.
 
 
Post #: 1
 
 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

(in reply to xybg5)
 
 
Post #: 2
 
 RE: Account Expiring Soon Script - 1/25/2008 4:38:00 AM   
  xybg5

 

Posts: 8
Score: 0
Joined: 1/24/2008
Status: offline
Ya, had tried that earlier but it still gives the same error.

(in reply to Rischip)
 
 
Post #: 3
 
 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

(in reply to xybg5)
 
 
Post #: 4
 
 RE: Account Expiring Soon Script - 1/25/2008 4:51:21 AM   
  xybg5

 

Posts: 8
Score: 0
Joined: 1/24/2008
Status: offline
Think I just found the problem. I was testing useing the wscrip command on a normal user account when I got the error. Logged onto my admin account and the script ran fine, so it was a permission issue, I assume with retrieving from the LDAP DB.

So my question now is, do logon scrips run as a system account or the users account? If I put this in for all users will they even be able to run it?
EDIT: Well, answerd my own question, still fails out. I'm assumeing the AD querys are not avaliable to normal users based on our security policy.

I can get the same information with dsquery and dsget but it prints in this format:

acctexpires
10/15/2008
dsget succeeded

Any way to strip the text from the date then use that in the calulations for the days left untill expiration? Looks like the .Run or .Exec command would run the DSquery/DSget inside of the script, or could be ran and the result piped to a text then pulled from there?

< Message edited by xybg5 -- 1/25/2008 6:36:42 AM >

(in reply to dm_4ever)
 
 
Post #: 5
 
 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

(in reply to xybg5)
 
 
Post #: 6
 
 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 >

(in reply to ebgreen)
 
 
Post #: 7
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Account Expiring Soon Script Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts