Click here to Skip to main content
       

Visual Basic

 
QuestionWeb interface to access application Pinmemberwaner michaud25-Feb-13 7:16 
AnswerRe: Web interface to access application PinmvpSandeep Mewara25-Feb-13 18:08 
GeneralRe: Web interface to access application Pinmemberwaner michaud26-Feb-13 3:13 
QuestionRe: Web interface to access application PinmvpSandeep Mewara26-Feb-13 3:16 
AnswerRe: Web interface to access application Pinmemberwaner michaud26-Feb-13 3:19 
AnswerRe: Web interface to access application Pinmemberwaner michaud26-Feb-13 5:40 
GeneralRe: Web interface to access application PinmvpSandeep Mewara26-Feb-13 5:52 
GeneralRe: Web interface to access application Pinmemberwaner michaud26-Feb-13 6:54 
AnswerRe: Web interface to access application PinmvpEddy Vluggen26-Feb-13 9:25 
QuestionListbox String to RichTextbox. Help Please! PinmemberJanko199322-Feb-13 17:14 
AnswerRe: Listbox String to RichTextbox. Help Please! PinmvpRichard MacCutchan22-Feb-13 23:21 
AnswerRe: Listbox String to RichTextbox. Help Please! PinmemberTnTinMN24-Feb-13 13:24 
GeneralRe: Listbox String to RichTextbox. Help Please! PinmemberGray_Ang3l24-Feb-13 13:29 
QuestionActive Directory Users OU Pinmemberdsj4122-Feb-13 8:14 
I'm trying to move disabled accounts in my active directory users OU. I'm getting a error message that says
 
Error: There is no such object on the server
Code: 80040E37
Source: Active Directory
 
I created a Test OU on the same level in active directory and I'm not having the same problem. Things work fine.
Error says it's from this line:

Set objRecordset = ObjCommand.Execute
 
Here's the code I'm using.
 
*************CODE*************
' Set Flag to enable the disabling and moving of unused accounts otherwise create
' log of accounts affected
' 1 - Will Disable and move accounts
' 0 - Will create ouput log only
bDisable=1


' Accounts that haven't been logged in for this amount of days are selected
iLogonDays=60
 
' LDAP Location of OUs to search for accounts
' LDAP location format eg: "OU=Users,OU=Test"
strSearchOU="OU=Users"
 
' Search depth to find users
' Use "OneLevel" for the specified OU only or "Subtree" to search all child OUs as well.
strSearchDepth="OneLevel"


' Location of new OU to move disabled user accounts to
' eg: "OU=Disabled_Accounts,OU=Test"
strNewOU="OU=Disabled_Accounts"
 
' Log file and error log file path
strLogPath=".\logs\"
' Error log file name appended with date and .err extension)
strErrorLog="DisabledAccounts_"
' Output log file name with date and .log extension)
strOutputLog="DisabledAccounts_"

sDate = Year(Now()) & Right("0" & Month(Now()), 2) & Right("0" & Day(Now()), 2)
Set oFSO=CreateObject("Scripting.FileSystemObject")
If Not oFSO.FolderExists(strLogPath) Then CreateFolder(strLogPath)
Set output=oFSO.CreateTextFile(strLogPath & strOutputLog & sDate & ".log")
Set errlog=oFSO.CreateTextFile(strLogPath & strErrorLog & sDate & ".err")
output.WriteLine "Sam Account Name" &vbTab& "LDAP Path" &vbTab& "Last Logon Date" &vbTab& _
"Date Created" &vbTab& "Home Directory"
errlog.WriteLine "Sam Account Name" &vbTab& "LDAP Path" &vbTab& "Problem" &vbTab& "Error"
 
Set rootDSE = GetObject("LDAP://rootDSE")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set ObjCommand = CreateObject("ADODB.Command")
ObjCommand.ActiveConnection = objConnection
ObjCommand.Properties("Page Size") = 10
DSEroot=rootDSE.Get("DefaultNamingContext")

Set objNewOU = GetObject("LDAP://" & strNewOU & "," & DSEroot)
ObjCommand.CommandText = ";(&(objectClass=User)(objectcategory=Person));adspath;" & strSearchDepth

Set objRecordset = ObjCommand.Execute

On Error Resume Next

While Not objRecordset.EOF
LastLogon = Null
intLogonTime = Null

Set objUser=GetObject(objRecordset.fields("adspath"))

If DateDiff("d",objUser.WhenCreated,Now) > iLogonDays Then
Set objLogon=objUser.Get("lastlogontimestamp")
If Err.Number <> 0 Then
WriteError objUser, "Get LastLogon Failed"
DisableAccount objUser, "Never"
Else
intLogonTime = objLogon.HighPart * (2^32) + objLogon.LowPart
intLogonTime = intLogonTime / (60 * 10000000)
intLogonTime = intLogonTime / 1440
LastLogon=intLogonTime+#1/1/1601#

If DateDiff("d",LastLogon,Now) > iLogonDays Then
DisableAccount objUser, LastLogon
End If
End If
End If
WriteError objUser, "Unknown Error"
objRecordset.MoveNext
Wend

Sub CreateFolder( strPath )
If Not oFSO.FolderExists( oFSO.GetParentFolderName(strPath) ) Then Call _
CreateFolder( oFSO.GetParentFolderName(strPath) )
oFSO.CreateFolder( strPath )
End Sub

Sub DisableAccount( objUser, lastLogon )
On Error Resume Next
If bDisable <> 0 Then
If objUser.accountdisabled=False Then
objUser.accountdisabled=True
objUser.SetInfo
WriteError objUser, "Disable Account Failed"
objNewOU.MoveHere objUser.adspath, "CN="&objUser.CN
WriteError objUser, "Account Move Failed"
Else
Err.Raise 1,,"Account already disabled. User not moved."
WriteError objUser, "Disable Account Failed"
End If
End If
output.WriteLine objUser.samaccountname &vbTab& objUser.adspath &vbTab& lastLogon &vbTab& _
objUser.whencreated &vbTab& objUser.homedirectory
End Sub

Sub WriteError( objUser, strProblem )
If Err.Number <> 0 Then
errlog.WriteLine objUser.samaccountname &vbTab& objUser.adspath &vbTab& strProblem &vbTab& _
Replace(Err.Description,vbCrlf,"")
Err.Clear
End If
End Sub
*********END CODE**********
AnswerRe: Active Directory Users OU PinmvpDave Kreskowiak22-Feb-13 8:45 
GeneralRe: Active Directory Users OU Pinmemberdsj4124-Feb-13 11:20 
GeneralRe: Active Directory Users OU PinmvpDave Kreskowiak25-Feb-13 10:31 
GeneralRe: Active Directory Users OU Pinmemberdsj4126-Feb-13 0:14 
GeneralRe: Active Directory Users OU Pinmemberdsj415-Mar-13 1:43 
QuestionVolume Button in Text to Speech Convertor Pinmembersanju_na21-Feb-13 22:05 
QuestionHttpwebrequest + Socks5 Pinmembermathisderaltefuchs20-Feb-13 21:49 
AnswerRe: Httpwebrequest + Socks5 PinmvpRichard MacCutchan20-Feb-13 23:00 
QuestionHow can we read lengthy datas in Win Forms - more height than 780 in single page by scroll? PinmemberParamu197320-Feb-13 6:19 
AnswerRe: How can we read lengthy datas in Win Forms - more height than 780 in single page by scroll? PinmvpEddy Vluggen20-Feb-13 6:39 
GeneralRe: How can we read lengthy datas in Win Forms - more height than 780 in single page by scroll? PinmemberParamu197320-Feb-13 18:50 
GeneralRe: How can we read lengthy datas in Win Forms - more height than 780 in single page by scroll? PinmvpEddy Vluggen21-Feb-13 7:03 
QuestionMaximize MDIParent and MDIChild control Pinmemberkurja-kurdoh19-Feb-13 6:41 
AnswerRe: Maximize MDIParent and MDIChild control PinmemberSimon_Whale19-Feb-13 21:58 
QuestionDisable local accounts Pinmemberdouglas.s.johnson@l-3com.com19-Feb-13 5:57 
AnswerRe: Disable local accounts PinmvpEddy Vluggen20-Feb-13 0:32 
GeneralRe: Disable local accounts Pinmemberdsj4120-Feb-13 11:22 
QuestionMenuId saved in Mysql DB and how to set Enable Pinmemberpalur198118-Feb-13 1:31 
AnswerRe: MenuId saved in Mysql DB and how to set Enable PinmvpEddy Vluggen18-Feb-13 22:31 
QuestionAnyone have a program where I can enter a username and have it provide info from Active Directory? Pinmemberanoble115-Feb-13 5:45 
AnswerRe: Anyone have a program where I can enter a username and have it provide info from Active Directory? PinmvpDave Kreskowiak15-Feb-13 6:40 
AnswerRe: Anyone have a program where I can enter a username and have it provide info from Active Directory? PinmemberSimon_Whale15-Feb-13 14:17 
Questionmathematical expression with custom user input operand separately Pinmemberarave052114-Feb-13 6:12 
AnswerRe: mathematical expression with custom user input operand separately PinmemberJibesh15-Feb-13 7:57 
AnswerRe: mathematical expression with custom user input operand separately PinmvpEddy Vluggen15-Feb-13 10:17 
QuestionZoom in / Zoom Out functions Pinmembersyllar12-Feb-13 21:55 
AnswerRe: Zoom in / Zoom Out functions PinmvpDave Kreskowiak13-Feb-13 2:07 
AnswerRe: Zoom in / Zoom Out functions PinmemberSimon_Whale13-Feb-13 2:23 
QuestionEditing columns in a CSV File PinmemberMike Prophete12-Feb-13 11:29 
AnswerRe: Editing columns in a CSV File PinmvpEddy Vluggen13-Feb-13 9:13 
AnswerRe: Editing columns in a CSV File PinmvpMichael Haephrati מיכאל האפרתי20-Feb-13 3:57 
QuestionHelp required in grid conditon Pinmembersiddisagar12-Feb-13 4:09 
Questionant colony algorithm Pinmembershowdowngh12-Feb-13 3:20 
AnswerRe: ant colony algorithm PinmemberSimon_Whale12-Feb-13 3:57 
AnswerRe: ant colony algorithm PinmvpDave Kreskowiak12-Feb-13 11:47 
QuestionHow to add Listview subitem with For Loop Pinmemberkurja-kurdoh9-Feb-13 17:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 23 Jul 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid