Question : Can't get script to create or write to UsersToDisable.txt on file server

I can't get the script to create or write to the UsersToDisable.txt on the file server. I'm using the cut off date of 18-Jul-2010 to test it. There is no value in the wWWHomePage atribute. What am I missing?


Dim objSysInfo ,objUser ,strwWWHomePage,strUserDN,ppt, strMbox

Set objSysInfo = CreateObject("ADSystemInfo")
strUserDN = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUserDN)

' Enable error handling
On Error Resume Next
' First command resets the value of the variable to ""
' Second attempts to set it with the value from AD
' If the second fails the variable will still be set to ""
strwWWHomePage = "" : strwWWHomePage = objUser.Get("wWWHomePage")
' Disable error handling
On Error Goto 0

dteCutOffDate = CDate("18-Jul-2010")

intDaysLeft = DateDiff("d", Now, dteCutOffDate)

If intDaysLeft > 0 Then
      ' Test the value in the variable
      If strwWWHomePage = "" Then
        Set ppt = CreateObject("PowerPoint.Application")
        strMbox = MsgBox("You have " & intDaysLeft & " days to complete this mandatory training or your account will be locked. Click OK to start PowerPoint presentation")
        ppt.Visible = True
        ppt.Presentations.Open "\\serverxx\tracking\ppt.ppsx"
      Else
            Set objFSO = CreateObject("Scripting.FileSystemObject")
            Const intForAppending = 8
            strDisableAccountsFile = "\\serverxx\tracking\UsersToDisable.txt"
            Set objFile = objFSO.CreateTextFile(strDisableAccountsFile, intForAppending, True)
            objFile.WriteLine strUserDN
            objFile.Close
        'objUser.AccountDisabled = True
        'objUser.SetInfo
            wscript.quit
      End If
End If


Answer : Can't get script to create or write to UsersToDisable.txt on file server

Hi, the script will only create the file if there *is* something in the wwwHomePage attribute.

If I remember correctly, when the user finishes viewing the PPT, you will write a value into the wwwHomePage attribute.

So, here is what the script currently does:
1) If the current date is past the cut off date, do nothing.
2) If the cutoff date has not been reached, and there is no wwwHomePage value (that is, the user has NOT viewed the PPT), then show the PPT.
3) If the cutoff date has not been reached, and there is a wwwHomePage value (that is, the user HAS viewed the PPT), then write to the file to inform Admins to disable the account.

Reading that, I don't think that's actually what you need.  Here is what I think you do need:
1) If there is NOT a value in wwwHomePage, and the cutoff date has not been reached, show the PPT
2) If there is NOT a value in wwwHomePage, and the cutoff date has been reached, write to the file to disable the account.
3) If there IS a value in wwwHomePage, do nothing, because the PPT has been viewed

So, I have re-ordered the script to suit that.

What I have realised you will need to do, is run the script I gave you to read the Disabled user accounts, on a daily basis, or maybe more if you like, because the user accounts won't be written there until each user logs in, and this may take a while if you have users away for a while.

Also, feel free to test this before closing the question.  You are welcome to ask for clarification and fixes, if this does not do what you need.

Regards,

Rob.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
Dim objSysInfo ,objUser ,strwWWHomePage,strUserDN,ppt, strMbox

Set objSysInfo = CreateObject("ADSystemInfo")
strUserDN = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUserDN)

' Enable error handling
On Error Resume Next
' First command resets the value of the variable to ""
' Second attempts to set it with the value from AD
' If the second fails the variable will still be set to ""
strwWWHomePage = "" : strwWWHomePage = objUser.Get("wWWHomePage")
' Disable error handling
On Error Goto 0

dteCutOffDate = CDate("18-Jul-2010")

intDaysLeft = DateDiff("d", Now, dteCutOffDate)

' Test the value in the variable
If strwWWHomePage = "" Then
	If intDaysLeft > 0 Then
		Set ppt = CreateObject("PowerPoint.Application")
		strMbox = MsgBox("You have " & intDaysLeft & " days to complete this mandatory training or your account will be locked. Click OK to start PowerPoint presentation")
		ppt.Visible = True
		ppt.Presentations.Open "\\serverxx\tracking\ppt.ppsx"
	Else
		Set objFSO = CreateObject("Scripting.FileSystemObject")
		Const intForAppending = 8
		strDisableAccountsFile = "\\serverxx\tracking\UsersToDisable.txt"
		Set objFile = objFSO.CreateTextFile(strDisableAccountsFile, intForAppending, True)
		objFile.WriteLine strUserDN
		objFile.Close
		'objUser.AccountDisabled = True
		'objUser.SetInfo
	End If
End If
Random Solutions  
 
programming4us programming4us