Visual Basic 2008 and Active Directory computer descriptionmodifications

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • brett

    Visual Basic 2008 and Active Directory computer descriptionmodifications

    ok, it appears that i have run into a spot that i am not able to
    figure out on my own. Let me first say that i have hobbled together
    this SUB from things i found on the internet and tutorials. Here is my
    issue...I can search AD for the description of the computer and
    display it out but am unable to figure out if the

    "
    If dirEntry.Proper ties.Contains(" description") Then
    dirEntry.Proper ties("descripti on")(0) = "Turek, Brett
    - Dell Laptop - Modified by VB program"
    Else
    dirEntry.Proper ties("descripti on").Add("Turek , Brett -
    Dell Laptop - Modified by VB program")
    End If
    dirEntry.Commit Changes()
    "

    part will actually do what i want, change the description in AD of the
    computer. Can anyone look this over and let me know if i am on the
    right path? How about some examples of how to change things in AD?

    *************** ****
    Complete Code:
    *************** ****
    Imports System
    Imports System.Manageme nt
    Imports System.Windows. Forms
    Imports System.Director yServices

    Public Sub Button5_Click(B yVal sender As Object, ByVal e As EventArgs)
    Handles Button5.Click
    'Rename Machine
    'SHELL("NETDOM RENAMECOMPUTER /NewName:" + TextBox3.Text + " /
    UserD:domain\us ername /PasswordD:passw ord /Force /Reboot:300")

    'Rename Description
    Dim userID = "Domain\usernam e"
    Dim password = "PASSWORD"
    Dim dirEntry As New DirectoryEntry( "LDAP://
    OU=Computers,OU =Abingdon,OU=MA R,OU=Customer,D C=us,DC=company ,DC=com",
    userID, password)
    Dim mySearcher As DirectorySearch er = New
    DirectorySearch er(dirEntry)

    mySearcher.Filt er = String.Format(" (CN=computerNam e)")
    mySearcher.Prop ertiesToLoad.Ad d("cn")
    mySearcher.Prop ertiesToLoad.Ad d("description" )

    Dim resEnt As SearchResult
    resEnt = mySearcher.Find One

    If resEnt Is Nothing Then
    MsgBox("User not found")
    Else
    MsgBox("Found: " +
    resEnt.GetDirec toryEntry().Pro perties("cn").V alue + " :: " +
    resEnt.GetDirec toryEntry().Pro perties("descri ption").Value)
    If dirEntry.Proper ties.Contains(" description") Then
    dirEntry.Proper ties("descripti on")(0) = "Turek, Brett
    - Dell Laptop - Modified by VB program"
    Else
    dirEntry.Proper ties("descripti on").Add("Turek , Brett -
    Dell Laptop - Modified by VB program")
    End If
    dirEntry.Commit Changes()

    MsgBox(resEnt.G etDirectoryEntr y().Properties( "description"). Value)
    End If
    End Sub
  • Cor Ligthert[MVP]

    #2
    Re: Visual Basic 2008 and Active Directory computer description modifications

    Brett,

    I am not sure what you try to achieve.

    The directory.servi ce is for your active directory


    The my class (my.computer my.user) a special VB class is

    for your computer






    Cor


    "brett" <planetbrett@gm ail.comschreef in bericht
    news:ad101ac7-05d0-402f-9132-679b23516102@i7 6g2000hsf.googl egroups.com...
    ok, it appears that i have run into a spot that i am not able to
    figure out on my own. Let me first say that i have hobbled together
    this SUB from things i found on the internet and tutorials. Here is my
    issue...I can search AD for the description of the computer and
    display it out but am unable to figure out if the
    >
    "
    If dirEntry.Proper ties.Contains(" description") Then
    dirEntry.Proper ties("descripti on")(0) = "Turek, Brett
    - Dell Laptop - Modified by VB program"
    Else
    dirEntry.Proper ties("descripti on").Add("Turek , Brett -
    Dell Laptop - Modified by VB program")
    End If
    dirEntry.Commit Changes()
    "
    >
    part will actually do what i want, change the description in AD of the
    computer. Can anyone look this over and let me know if i am on the
    right path? How about some examples of how to change things in AD?
    >
    *************** ****
    Complete Code:
    *************** ****
    Imports System
    Imports System.Manageme nt
    Imports System.Windows. Forms
    Imports System.Director yServices
    >
    Public Sub Button5_Click(B yVal sender As Object, ByVal e As EventArgs)
    Handles Button5.Click
    'Rename Machine
    'SHELL("NETDOM RENAMECOMPUTER /NewName:" + TextBox3.Text + " /
    UserD:domain\us ername /PasswordD:passw ord /Force /Reboot:300")
    >
    'Rename Description
    Dim userID = "Domain\usernam e"
    Dim password = "PASSWORD"
    Dim dirEntry As New DirectoryEntry( "LDAP://
    OU=Computers,OU =Abingdon,OU=MA R,OU=Customer,D C=us,DC=company ,DC=com",
    userID, password)
    Dim mySearcher As DirectorySearch er = New
    DirectorySearch er(dirEntry)
    >
    mySearcher.Filt er = String.Format(" (CN=computerNam e)")
    mySearcher.Prop ertiesToLoad.Ad d("cn")
    mySearcher.Prop ertiesToLoad.Ad d("description" )
    >
    Dim resEnt As SearchResult
    resEnt = mySearcher.Find One
    >
    If resEnt Is Nothing Then
    MsgBox("User not found")
    Else
    MsgBox("Found: " +
    resEnt.GetDirec toryEntry().Pro perties("cn").V alue + " :: " +
    resEnt.GetDirec toryEntry().Pro perties("descri ption").Value)
    If dirEntry.Proper ties.Contains(" description") Then
    dirEntry.Proper ties("descripti on")(0) = "Turek, Brett
    - Dell Laptop - Modified by VB program"
    Else
    dirEntry.Proper ties("descripti on").Add("Turek , Brett -
    Dell Laptop - Modified by VB program")
    End If
    dirEntry.Commit Changes()
    >
    MsgBox(resEnt.G etDirectoryEntr y().Properties( "description"). Value)
    End If
    End Sub

    Comment

    • brett

      #3
      Re: Visual Basic 2008 and Active Directory computer descriptionmodi fications

      I found this article that helped a little.

      Find answers to Active Directory Properties not displaying correctly using DirectoryEntry Properties from the expert community at Experts Exchange


      My new SUB looks like this and it works:

      Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
      System.EventArg s)
      'Rename Machine
      'SHELL("NETDOM RENAMECOMPUTER /NewName:" + TextBox3.Text + " /
      UserD:domain\us ername /PasswordD:passw ord /Force /Reboot:300")

      Try
      'Rename Description
      Dim userID = "domain\usernam e"
      Dim password = "password"
      Dim dirEntry As New DirectoryEntry( "LDAP://
      OU=Computers,OU =Abingdon,OU=MA R,OU=Customer,D C=us,DC=company ,DC=com",
      userID, password)
      Dim mySearcher As DirectorySearch er = New
      DirectorySearch er(dirEntry)

      mySearcher.Filt er = String.Format(" (CN=computerNam e)")
      mySearcher.Prop ertiesToLoad.Ad d("cn")
      mySearcher.Prop ertiesToLoad.Ad d("description" )

      Dim resEnt As SearchResult
      resEnt = mySearcher.Find One()

      If resEnt Is Nothing Then
      MsgBox("Compute r not found")
      Else
      MsgBox("Found: " +
      resEnt.GetDirec toryEntry().Pro perties("cn").V alue + " :: " +
      resEnt.GetDirec toryEntry().Pro perties("descri ption").Value)
      'dirEntry.Prope rties("descript ion").Add("Ture k, Brett
      - Dell Laptop - Modified by VB program")
      'dirEntry.Commi tChanges()

      'echo out after changes - doesnt work
      'MsgBox("Change 1: " +
      resEnt.GetDirec toryEntry().Pro perties("descri ption").Value)

      'new commit change works
      Dim newComputerDesc =
      dirEntry.Childr en.Find("CN=com puterName", "computer")
      newComputerDesc .Properties("de scription").Val ue =
      "Turek, Brett - Dell Laptop"
      newComputerDesc .CommitChanges( )

      'echo out after changes
      'MsgBox("Change 2: " +
      resEnt.GetDirec toryEntry().Pro perties("descri ption").Value)
      End If
      Catch generatedExcept ionName As Exception
      MsgBox(generate dExceptionName)
      End Try
      End Sub

      Comment

      Working...